Don't like banner ads in your Web browser? Pop-up blocking just not enough for you?

What if you could prevent your computer from contacting ad servers at all? You can, if you're running Mac OS X (or 7, 8, or 9, or Windows, or any other modern OS you can name).

This document will explain, in a small compartment inside a nutshell, how to enable and configure your hosts file to block ad banners from appearing in all browsers.

Note: This document assumes a semi-basic level of computer savvy and a level of comfort operating in the Terminal.


/etc/hosts

First, what is a hosts file?

Every time your computer looks for, say, apple.com, it asks your ISP's domain name servers to resolve the name "apple.com" to a numerical address called an IP address. If you have "apple.com" listed in your computer's hosts file, your computer will not query the name server, instead going to the IP address specified in the hosts file entry.

The hosts file is located in "/etc"; its full path is "/etc/hosts".

An example /etc/hosts entry looks like this:

0.0.0.0 ad.doubleclick.net

In this example, I've told the computer to look to the IP address "0.0.0.0" every time it needs to find "ad.doubleclick.net". This IP address, 0.0.0.0, goes nowhere, and will result in nothing being found. Doubleclick.net's server isn't even queried, because the query never escapes my computer.

So how do you use this information to your advantage?

By adding the names of ad servers to this file along side the IP black hole of 0.0.0.0, you can progessively and selectively eliminate the banner ads you see in any Web browser, including the ever-crappy Internet Explorer, which can't even block pop-up ads on its own, let alone banner ads.


The Dirty Work

You can edit /etc/hosts with any text editor that can authenticate with an administrator's password to gain write rights on the /etc/hosts file, as the file is owned by root and doesn't allow anyone but root to alter it. I usually use BBEdit to do this, but you can also use pico or vi or whatever you like.

No matter what text editor you use, you'll need one that can authenticate you as the administrator user when you click "save" (like BBEdit). If you're not an administrator, you're out of luck here. Talk to your administrator.

As your text editor opens up /etc/hosts, you will see text already there. Do not alter the existing text. Add your ad server entries below what's already written in the file. If you alter the defaults, you could crippled your computer's ability to connect to networks--say, for example, that new thing the kids call the Internet--at all.

Your default setup there might resemble this:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost

Don't touch 'em.

Under the last entry in the file, add the new ad server black hole by first typing the 0.0.0.0 IP address at the beginning of the line, typing a space, and then typing the name of the ad server you wish to block. Do this for as many ad servers as you like, starting a new line for each one.

When you're done, it will resemble this:

0.0.0.0 ad.dumbadserver.net

If you want to add non-entry reminders, descriptions, or other comments, precede the line with a pound symbol (#) to "comment out" the line.

#this is an example of a comment, and it will be ignored during lookup requests

Save your work, authenticating if asked to authenticate by your text editor.

Your hosts file has been updated, but it won't work! Ack! Why? You need to enable the so-called "BSD flat files"--things like /etc/hosts--in an application called Directory Access. This application is located inside the Utilities folder, inside Applications (/Applications/Utilities/Directory Access).

Once you open this program, click the lock in the bottom-left corner to authenticate.

Check the box next to "BSD Configuration Files" and quit Directory Access.

Note: As of Mac OS X 10.3, the BSD flat files are enabled by default.

You're done! Woot! However, remember that any domain name you put in /etc/hosts will not be reachable as long as the BSD config files are enabled and the domain name is in said hosts file. Don't go putting your mail server in there because you don't like spam, or you'll never see mail again. ;-)

Now that we're done with that, here's my current ad server blocking list. Copy and paste into your hosts file and say good-bye to most banner ads. I've compiled it from several places (for example, the majority of it is from everythingisnt.com), so it's pretty diesel, but I'm always on the lookout for more servers I can add. I'll update it as often as I change it on my computer, so keep checking back for changes.

-/-
Mikey-San
org dot bungie at mikey-san

Instructions updated: 02 May 2003
Hosts file last updated: 23 November 2003