Tuesday, June 3, 2008

Tweak your host file to block ad generating web sites

Here is a cool tip to block ad generating websites from serving ads while you are browsing the web. The idea is to direct all the domains pointing to the ad serving sites to your localhost aka 127.0.0.1 . Now, the next time you visit a website and the website is serving an ad from a domain which you have directed to your localhost, you will see a blank space at the position where the ad was to be served.

This is done by inserting lines in your host file (/etc/hosts) on your Linux machine which are in the following format one domain per line :

FILE: /etc/hosts
127.0.0.1 localhost
127.0.0.1 ad.doubleclick.net
127.0.0.1 xx.adserver.xxx
...
... and so on.

One thing worth noting is that once you have collected (almost) all the ad serving sites domains, the resulting host file will be really huge as there are an ever growing collection of companies which make a living serving ads on publishing sites. More over, after some time it gets a bit tedious to update the /etc/hosts file on a regular basis.

LittleUbuntu has a nice writeup about implementing this feature in Ubuntu as well as a link to the original article.

No comments: