PCHF Newsletter:  
Become a Fan of PCHF on Facebook!
User Reviews - Add Yours!
The PCHF Lounge

Web Tutorials

Email This Post Email This Post Print This Post Print This Post Post a commentPost a Comment

Blocking ads on the Internet

By: MadMonkey | Posted 05.1. 2009
blocked

Blocked

Here’s a tutorial on how to block adverts on the internet by hostnames and IP addresses, in just 4 easy steps!

So, to start blocking ads:

bullet Find your hosts file.
bullet Download the list of ad servers.
bullet copy the list of ad servers on the end of your hosts file (see Where’s my hosts file? if you don’t know where it is).
bullet Restart your browser.
How it works

It’s possible to set up a name server as authoritative for any domain you choose, allowing you to specify the DNS records for that domain. You can also configure most computers to be sort of mini-nameservers for themselves, so that they check their own DNS records before asking a nameserver.  Either way, you get to say what hostname points to what IP address. If you haven’t guessed already, the way you block ads it to provide bogus information about the domains we don’t want to see - ie, all those servers out there that dedicate their existence to spewing out banner ads.
The hosts file

Probably the most common way people block ads like this is with something called the “hosts file”.  The hosts file is a simple list of hostnames and their corresponding IP addresses, which your computer looks at every time you try and contact a previously unknown hostname.  If it finds an entry for the computer you’re trying to reach, it sets the IP address for that computer to be whatever’s in the hosts file.

127.0.0.1 is a special IP address which, to a computer, always means that computer. Any time a machine sends a network request to 127.0.0.1, it is talking to itself. This is very useful when it comes to blocking ads, because all we have to do is specify the IP address of any ad server to be 127.0.0.1. And to do that, all we have to do is edit the hosts file. What will happen then is something like this:

bullet You visit a web page
bullet The web page contains a banner ad stored on the server “ads.example.com”
bullet Your computer says “ads.example.com? never heard of it. wait a second, let’s see if I’ve got the number on me…”
bullet Your computer finds its hosts file and checks to see if ads.example.com is listed.
bullet it finds the hostname, which points to 127.0.0.1
bullet “great”, says the computer, and sends off a request to 127.0.0.1 for the banner ad that’s supposed to be on the page.
bullet “oh”, says the computer, and fails to show anything because it just sent a request to itself for a banner ad
Where’s my hosts file?
Windows 95 / 98 / ME: C:\Windows (I believe)
Windows NT: C:\WinNT\hosts
Windows 2000: C:\WinNT\system32\drivers\etc\
Windows XP: C:\Windows\System32\drivers\etc\
Windows Vista: C:\Windows\System32\drivers\etc\
FreeBSD / Linux / Mac OS X / Unixish operating systems: /etc/hosts
Classic Mac OS: please read this helpful information submitted by David “iNerd” B
Mac OS 9: Marcia Skidmore sent in details that hopefully explain what you need to know

The format of the hosts file is very simple - IP address, whitespace, then a list of hostnames (except for older Macs; please see above). However, you don’t need to know anything about the format if you don’t want to as you can just view the list hosts file.

Of course, that’s not the only way to use the list, but it’s probably the most simple for most people.

About the list

Why would anyone want a list of hostnames?

The ad banners that you see all over the web are stored on servers. Stopping your computer communicating with another computer can be quite simple. So, if you have a list of the servers used for ad banners, it’s easy to stop ad banners even getting to your browser.

But ad banners don’t bother me?

If ad banners aren’t a problem for you, then these pages aren’t really going to do much for you. But personally, I hate them. I’ve never got used to having flashing images in the corner of my vision when I’m trying to read. Imagine if real books came with neon lights that blinked messages at you over and over again. And imagine that every time you turned the page, you had to wait a few seconds whilst they changed from neon green to neon yellow. And then they’d send the title of the book, your reading speed, and what chapters you’ve skipped to the central Library so that they can sell the information to all the big bookstores. Reading real books would be even more unpopular than it is now! But, I guess, maybe it wouldn’t - millions of people do exactly the same thing on the Interweb every day (if you substitute the book for a web site).

Why do we do it to ourselves?

We need to stop this. It’s time to rise up! Let us be blinked at no longer! Let the flashing cease! Down with banners! Up with transfer rates! STOP THE MADNESS!

And, Brothers and Sisters, the first step starts with YOU. Blocking ads makes sense! Start today!

Isn’t this a bit much for a list of hostnames?

I started doing this a while ago, and thought I’d put my list up on the Interweb for everyone to use. That was way back in the mists of ‘Net time, when the Interweb was just the Web, and dotcoms were still getting funding. Eons later, a simple list of hostnames has evolved in to what you see before you. I guess it just goes to show - even the tiniest amoebic piece of slime can become the President of the USA if you leave it alone long enough.

Why not just use JunkBuster / Ad-aware / some other piece of software?

There’s lots of great ad blocking software out there that’s probably far more effective than just using this list. But there are also disadvantages to using these pieces of software, and sometimes people are unable to use them:

bullet Some methods produce false positives - eg, if you were blocking all hostnames beginning with “adservers”, you wouldn’t be able to get to this list by its usual URL (http://pgl.yoyo.org/adservers/ - which, incidentally, is why you can also get to this list via http://pgl.yoyo.org/as/)

bullet Some methods require administrative privileges - using this list as a proxy autoconfig script means that users of most browsers can use it even if they’re not administrators; installing programs and editing system files can often be restricted

bullet Some programs don’t support all operating systems - eg, Ad-aware, a brilliant program, is only available for Win32 operating systems

But in any case, I’m not saying this list is definitely going to be useful to you.  It’s just here because it was easy for me to put it up, and there’s been enough interest for me to keep updating things. If you’re not interested, don’t use it!

From, and more info here:  http://pgl.yoyo.org/adservers/

Tags: , ,



Featured Article

Windows 7 RC is Dying!

By: admin
Posted 02.7. 2010

Still sporting your far from shiny (now) copy of Windows 7 Release Candidate? Life’s good then - right? Well, actually no, life is about to get a bit complicated for you over the next month or so….

Beginning on Feb. 15, 2010:
An expiration notification pops up in the task bar once a day.
The Notification Wizard alerts [...]

Read More »

PCHF on FacebookPCHF on Twitter

PCHF Articles Feed PCHF Forum Feeds PCHF Tutorials Feed PCHF Files Feed

Join the PCHF Staff Team
PCHF on TV
GoToMyPC Pro
  • Which Internet search engine do you use most?

    View Results

    Loading ... Loading ...


PCHF Newsletter