Most modern operating systems use a 'hosts' file, or some varient. What this 'hosts' file does is explained in /etc/hosts.

Using the hosts file on your system to redirect the hostname of banner ad servers to 127.0.0.1 (your computer), you can prevent many banner ads for ever getting a chance of loading. Put simply, you can use this to block a lot of ads from websites without extra software and minimal effort.


Step 1:

Open up your system's hosts file. Depending on your operating system, it may be any of the following.

Windows NT/2000 - c:\winnt\system32\drivers\etc\hosts

Windows XP - c:\windows\system32\drivers\etc\hosts

Linux/BSD/Solaris/*n?x - /etc/hosts

BeOS - /boot/beos/etc/hosts

(Some of these systems may not allow you to view or edit the hosts file unless you are root/administrator)

The file will probably be little more then 127.0.0.1 localhost.


Step 2:

With that file open on your system, paste the following into it below the 127.0.0.1 localhost bit.

    127.0.0.1       207-87-18-203.wsmg.digex.net
    127.0.0.1       Garden.ngadcenter.net
    127.0.0.1       Ogilvy.ngadcenter.net
    127.0.0.1       ResponseMedia-ad.flycast.com
    127.0.0.1       Suissa-ad.flycast.com
    127.0.0.1       UGO.eu-adcenter.net
    127.0.0.1       VNU.eu-adcenter.net
    127.0.0.1       a32.g.a.yimg.com
    127.0.0.1       ad-adex3.flycast.com
    127.0.0.1       ad.abcnews.com
    127.0.0.1       ad.adsmart.net
    127.0.0.1       ad.au.doubleclick.net
    127.0.0.1       ad.ca.doubleclick.net
    127.0.0.1       ad.de.doubleclick.net
    127.0.0.1       ad.doubleclick.net
    127.0.0.1       ad.fr.doubleclick.net
    127.0.0.1       ad.icq.com
    127.0.0.1       ad.jp.doubleclick.net
    127.0.0.1       ad.keenspace.com
    127.0.0.1       ad.linkexchange.com
    127.0.0.1       ad.linksynergy.com
    127.0.0.1       ad.nl.doubleclick.net
    127.0.0.1       ad.no.doubleclick.net
    127.0.0.1       ad.preferences.com
    127.0.0.1       ad.sma.punto.net
    127.0.0.1       ad.trafficmp.com
    127.0.0.1       ad.uk.doubleclick.net
    127.0.0.1       ad.webprovider.com
    127.0.0.1       ad08.focalink.com
    127.0.0.1       adcontroller.unicast.com
    127.0.0.1       adcreatives.imaginemedia.com
    127.0.0.1       adex3.flycast.com
    127.0.0.1       adforce.ads.imgis.com
    127.0.0.1       adforce.imgis.com
    127.0.0.1       adfu.blockstackers.com
    127.0.0.1       adimage.blm.net
    127.0.0.1       adimages.earthweb.com
    127.0.0.1       adimg.egroups.com
    127.0.0.1       admedia.xoom.com
    127.0.0.1       adpick.switchboard.com
    127.0.0.1       adremote.pathfinder.com
    127.0.0.1       ads.ad-flow.com
    127.0.0.1       ads.admaximize.com
    127.0.0.1       ads.admonitor.net
    127.0.0.1       ads.bfast.com
    127.0.0.1       ads.clickagents.com
    127.0.0.1       ads.clickhouse.com
    127.0.0.1       ads.enliven.com
    127.0.0.1       ads.fairfax.com.au
    127.0.0.1       ads.fool.com
    127.0.0.1       ads.freshmeat.net
    127.0.0.1       ads.hollywood.com
    127.0.0.1       ads.i33.com
    127.0.0.1       ads.icq.com
    127.0.0.1       ads.infi.net
    127.0.0.1       ads.jwtt3.com
    127.0.0.1       ads.link4ads.com
    127.0.0.1       ads.lycos.com
    127.0.0.1       ads.madison.com
    127.0.0.1       ads.mcafee.com
    127.0.0.1       ads.mediaodyssey.com
    127.0.0.1       ads.msn.com
    127.0.0.1       ads.musiccity.com
    127.0.0.1       ads.newcity.com
    127.0.0.1       ads.ninemsn.com.au
    127.0.0.1       ads.seattletimes.com
    127.0.0.1       ads.smartclicks.com
    127.0.0.1       ads.smartclicks.net
    127.0.0.1       ads.snowball.com
    127.0.0.1       ads.sptimes.com
    127.0.0.1       ads.tripod.com
    127.0.0.1       ads.web.aol.com
    127.0.0.1       ads.webcoretech.com
    127.0.0.1       ads.x10.com
    127.0.0.1       ads.xtra.co.nz
    127.0.0.1       ads.zdnet.com
    127.0.0.1       ads01.focalink.com
    127.0.0.1       ads02.focalink.com
    127.0.0.1       ads03.focalink.com
    127.0.0.1       ads04.focalink.com
    127.0.0.1       ads05.focalink.com
    127.0.0.1       ads06.focalink.com
    127.0.0.1       ads08.focalink.com
    127.0.0.1       ads09.focalink.com
    127.0.0.1       ads1.activeagent.at
    127.0.0.1       ads10.focalink.com
    127.0.0.1       ads11.focalink.com
    127.0.0.1       ads12.focalink.com
    127.0.0.1       ads14.focalink.com
    127.0.0.1       ads16.focalink.com
    127.0.0.1       ads17.focalink.com
    127.0.0.1       ads18.focalink.com
    127.0.0.1       ads19.focalink.com
    127.0.0.1       ads2.zdnet.com
    127.0.0.1       ads20.focalink.com
    127.0.0.1       ads21.focalink.com
    127.0.0.1       ads22.focalink.com
    127.0.0.1       ads23.focalink.com
    127.0.0.1       ads24.focalink.com
    127.0.0.1       ads25.focalink.com
    127.0.0.1       ads3.zdnet.com
    127.0.0.1       ads3.zdnet.com
    127.0.0.1       ads4.realcities.com
    127.0.0.1       ads5.gamecity.net
    127.0.0.1       adserv.iafrica.com
    127.0.0.1       adserv.quality-channel.de
    127.0.0.1       adserver.dbusiness.com
    127.0.0.1       adserver.garden.com
    127.0.0.1       adserver.janes.com
    127.0.0.1       adserver.matchcraft.com
    127.0.0.1       adserver.merc.com
    127.0.0.1       adserver.monster.com
    127.0.0.1       adserver.portalofevil.com
    127.0.0.1       adserver.track-star.com
    127.0.0.1       adserver1.backbeatmedia.com
    127.0.0.1       adserver1.ogilvy-interactive.de
    127.0.0.1       adtegrity.spinbox.net
    127.0.0.1       antfarm-ad.flycast.com
    127.0.0.1       au-ads.admonitor.net
    127.0.0.1       au.ads.link4ads.com
    127.0.0.1       banner.media-system.de
    127.0.0.1       banner.orb.net
    127.0.0.1       banner.relcom.ru
    127.0.0.1       banners.easydns.com
    127.0.0.1       banners.looksmart.com
    127.0.0.1       banners.stilenet.com
    127.0.0.1       banners.wunderground.com
    127.0.0.1       barnesandnoble.bfast.com
    127.0.0.1       beseenad.looksmart.com
    127.0.0.1       bizad.nikkeibp.co.jp
    127.0.0.1       bn.bfast.com
    127.0.0.1       c3.xxxcounter.com
    127.0.0.1       califia.imaginemedia.com
    127.0.0.1       cds.mediaplex.com
    127.0.0.1       click.avenuea.com
    127.0.0.1       click.go2net.com
    127.0.0.1       click.linksynergy.com
    127.0.0.1       cookies.cmpnet.com
    127.0.0.1       cornflakes.pathfinder.com
    127.0.0.1       counter.hitbox.com
    127.0.0.1       crux.songline.com
    127.0.0.1       erie.smartage.com
    127.0.0.1       etad.telegraph.co.uk
    127.0.0.1       fmads.osdn.com
    127.0.0.1       fp.valueclick.com
    127.0.0.1       gadgeteer.pdamart.com
    127.0.0.1       gamma.adroar.com
    127.0.0.1       global.msads.net
    127.0.0.1       gm.preferences.com
    127.0.0.1       gp.dejanews.com
    127.0.0.1       hg1.hitbox.com
    127.0.0.1       image.click2net.com
    127.0.0.1       image.eimg.com
    127.0.0.1       images.ads.fairfax.com.au
    127.0.0.1       images2.nytimes.com
    127.0.0.1       img-iad.wip.mediaplex.com
    127.0.0.1       jobkeys.ngadcenter.net
    127.0.0.1       kansas.valueclick.com
    127.0.0.1       leader.linkexchange.com
    127.0.0.1       liquidad.narrowcastmedia.com
    127.0.0.1       ln.doubleclick.net
    127.0.0.1       m.doubleclick.net
    127.0.0.1       m.tribalfusion.com
    127.0.0.1       macaddictads.snv.futurenet.com
    127.0.0.1       maximumpcads.imaginemedia.com
    127.0.0.1       media.preferences.com
    127.0.0.1       mercury.rmuk.co.uk
    127.0.0.1       mojofarm.sjc.mediaplex.com
    127.0.0.1       nbc.adbureau.net
    127.0.0.1       newads.cmpnet.com
    127.0.0.1       ng3.ads.warnerbros.com
    127.0.0.1       ngads.smartage.com
    127.0.0.1       nsads.hotwired.com
    127.0.0.1       ntbanner.digitalriver.com
    127.0.0.1       ph-ad05.focalink.com
    127.0.0.1       ph-ad07.focalink.com
    127.0.0.1       ph-ad16.focalink.com
    127.0.0.1       ph-ad17.focalink.com
    127.0.0.1       ph-ad18.focalink.com
    127.0.0.1       rd.advertising.com
    127.0.0.1       rd.yahoo.com
    127.0.0.1       realads.realmedia.com
    127.0.0.1       redherring.ngadcenter.net
    127.0.0.1       redirect.click2net.com
    127.0.0.1       regio.adlink.de
    127.0.0.1       retaildirect.realmedia.com
    127.0.0.1       s2.focalink.com
    127.0.0.1       servedby.advertising.com
    127.0.0.1       sh4sure-images.adbureau.net
    127.0.0.1       spin.spinbox.net
    127.0.0.1       st.clickagents.com
    127.0.0.1       st.valueclick.com
    127.0.0.1       static.admaximize.com
    127.0.0.1       stats.superstats.com
    127.0.0.1       sview.avenuea.com
    127.0.0.1       thinknyc.eu-adcenter.net
    127.0.0.1       tracker.clicktrade.com
    127.0.0.1       tribalfusion.speedera.net
    127.0.0.1       tsms-ad.tsms.com
    127.0.0.1       us.a1.yimg.com
    127.0.0.1       us.i1.yimg.com
    127.0.0.1       v0.extreme-dm.com
    127.0.0.1       v1.extreme-dm.com
    127.0.0.1       van.ads.link4ads.com
    127.0.0.1       view.accendo.com
    127.0.0.1       view.avenuea.com
    127.0.0.1       w113.hitbox.com
    127.0.0.1       w25.hitbox.com
    127.0.0.1       web2.deja.com
    127.0.0.1       webads.bizservers.com
    127.0.0.1       www.PostMasterBannerNet.com
    127.0.0.1       www.ad-up.com
    127.0.0.1       www.admex.com
    127.0.0.1       www.alladvantage.com
    127.0.0.1       www.burstnet.com
    127.0.0.1       www.commission-junction.com
    127.0.0.1       www.eads.com
    127.0.0.1       www.freestats.com
    127.0.0.1       www.imaginemedia.com
    127.0.0.1       www.netdirect.nl
    127.0.0.1       www.oneandonlynetwork.com
    127.0.0.1       www.targetshop.com
    127.0.0.1       www.teknosurf2.com
    127.0.0.1       www.teknosurf3.com
    127.0.0.1       www.valueclick.com
    127.0.0.1       www.websitefinancing.com
    127.0.0.1       www2.burstnet.com
    127.0.0.1       www4.trix.net
    127.0.0.1       www80.valueclick.com
    127.0.0.1       z.extreme-dm.com
    127.0.0.1       z0.extreme-dm.com
    127.0.0.1       z1.extreme-dm.com
    

Save the changes.

Now ads from any of those servers will be unable to load. (Some systems may require a reboot for changes to come into effect)


Step 3:

There is no step 3.


The list will always be incomplete; if you find an adserver hostname that is not on the list above, don't create a new writeup below, please /msg a God or Content Editor and ask them to add it.

Also, standard disclaimer: This is all at your own risk... blah blah etc. If using this makes your computer explode, don't blame me.

Have fun!


VirtualWolf: I didn't specify Mac OS because I couldn't test it myself. As far as I knew Classic Mac OS uses a different style of hosts file, and I just thought Mac OS X would be covered by the *n?x bit. It's not, though...

/me smacks Xenex

You forgot the Mac OS! :P

Under Mac OS X, being a *NIX variant, the hosts file is located at /etc/hosts. Under Mac OS X 10.2, lookupd is configured to look in /etc/hosts by default, however if you're running 10.0 or 10.1, /etc/hosts/ is completely ignored unless you're in single user mode. To get around this, you have to edit your /etc/hosts file as per normal, then type the command sudo niload < /etc/hosts. This reads /etc/hosts and puts it into the NetInfo database.

If you're running Mac OS 9, however, it's called "Hosts" and is located in the Preferences folder inside your System Folder. To use your Hosts file, open up the TCP/IP control panel, make sure that the User Mode is set to Advanced, click the Use Hosts File button, and select the Hosts file.

Actually, I just remembered something: when you select the Hosts file above, you can choose the file from anywhere (it doesn't have to been located in System Folder:Preferences). What it does is copies this file, renames it to "Hosts", and sticks it in Preferences.

Now you can enjoy Xenex's ad-blocking goodness from the comfort of your very own Mac!

A simple, 'no additional software' method of blocking adverts on the web is to alter the local 'hosts file', in order to redirect requests for the banner ads from the real server either to the local machine, or into oblivion, preventing the banner from being downloaded, and therefore displayed.

The hosts file is (for most operating systems) a text file, each line of which contains an ip address, followed by the hostnames it should override. Hosts files are normally used in small networks that are too small to justify a centralised DNS, to map hostnames to devices that don't participate in a peer-to-peer name resolution system. In commonly-used operating systems, the hosts file is found in the following places:

  • Windows 2000/XP: %windir%/system32/drivers/etc/hosts
  • Windows 95/98/ME: %windir%/hosts
  • Linux: /etc/hosts

This is not without its drawbacks. Quite a few web browsers (Netscape navigator especially) won't render the page until they have downloaded all the images and scripts the page needs to display. If one of these images or scripts is located on a server blocked using the hosts file, it will not render the page until it has timed out trying to contact all the blocked servers, often several times.

This problem can be circumvented, either by redirecting the requests to a nearby webserver, or by running a webserver on the local machine, and redirecting requests to it. The webserver on the local machine need not be particularly powerful (Personal Webserver will do; Apache is probably a bit overkill), or even a proper webserver (look elswhere in this node for a perl script that pretends to be a webserver).

Though it can be made to work acceptably, this method is nothing better than a hack. It is less useful on modern, multi-user operating systems, as the changes to the hosts file affect all users, and often cannot be effected without being root/administrator. In addition, there is no way to block adverts on the same host as wanted content (for example, there is no way to block http://www.example.com/ads/banner.gif without also blocking http://www.example.com/articles/interesting_article.html).

A much better solution is to use an advert-blocking proxy - privoxy is Free, and available for both windows and unix. As it matches URLs according to a list of regular expressions, it can block with much greater granularity than simply banning hosts. It can block patterns of URLs, catching all of a large ad company's servers in one line that does not need to be updated as the company moves its servers about. It serves replacement images (either transparent 'web bugs' to remove the banner entirely, or an unobtrusive checkerboard pattern, so that it is obvious that the page has been interfered with) for banners, so there are none of the 'time out' issues associated with host-based blocking. Privoxy can even alter the text of web-pages in transit to remove the place where the blocked advert would have been. Blocking and web-page altering use Perl's regular expression library, allowing for very powerful and customisable ad blocking and web-page alteration.

The hosts file does have its uses, however - several 'spyware' programs (creative labs media manager, gozilla, realplayer etc.) will attempt to 'phone home', sending personal information back to the authors, and providing no way of disabling this behaviour. In this case, adding a bogus entry for the 'phone home server to the hosts file will prevent the application from phoning home. In my opinion, the privacy benefits greatly outweigh the inconvenience of the program popping up a 'cannot connect to server' warning every so often.

I'm suprised nobody's mentioned it, but http://www.smartin-designs.com/ has a great regulary updated hosts file.

I wrote the following to help deal with browsers complaining about refused connections.

#!/usr/local/bin/perl -w
# simple HTTP server. Responds blindly with a 1x1 transparent PNG. Use with a hosts file for ad blocking

use IO::Socket;
use Net::hostent;

$server = IO::Socket::INET->new(
  Proto => 'tcp',
  LocalPort => 80,
  Listen    => SOMAXCONN,
  Reuse     => 1
) ;

print "*** fakehttp - listening on port 80\n";

while ($client = $server->accept()) {
  $client->autoflush(1);
  print "Recived a request, responding with 1x1 transparent png...\n";
  print $client "HTTP/1.1 200 OK\nContent-Length: 68\n".
"Content-Type: image/x-png\n\n\211\120\116\107\015\012".
"\032\012\000\000\000\015\111\110\104\122\000\000\000".
"\001\000\000\000\001\010\006\000\000\000\037\025\304".
"\211\000\000\000\013\111\104\101\124\170\001\143\140".
"\000\002\000\000\005\000\001\116\013\250\146\000\000".
"\000\000\111\105\116\104\256\102\140\202";
  close $client;
}

Log in or register to write something here or to contact authors.