display | more...

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 (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 localhost.

Step 2:

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

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