Hack 42. Surf the Internet Ad-Free
Cruising the Internet these days feels like a trip down the Las Vegas strip. Here's how you can turn off the ads and surf in peace.
There once was a day when advertising on the Web was limited to relatively small, discreet banners ads at the top of pages.
Those days are gone. Now ads are everywherebig ones embedded in the middle of the page, large ones running down the right column, and monster ones that seem to take up entire pages. Ads can be more than just annoying; web sites can also use them to track your surfing activities.
But you don't have to put up with it. You can surf the Internet ad-free. There are several ways to do it: either use ad-blocking software, or do some hacking of your system for free. Either way, you'll whack the ads.
4.12.1. Use a HOSTS File to Kill Ads
If you're looking for a free way to kill ads, using a HOSTS file is a great solution. This technique takes advantage of the fact that few web sites host their own ads. Instead, they generally use ad servers that deliver the ads. There aren't very many of these ad servers, so if you block those servers from delivering content to your PC, you'll block most of the ads on the Internet.
First, some background about HOSTS files. When you type in a URL such as http://www.oreilly.com, your PC needs to translate those letters into a numeric IP address that it can understand, such as 188.8.131.52. Doing this is called name resolution. DNS servers on the Internet provide name resolution automatically and behind the scenes as you surf the Web.
When you type in a URL, before your PC contacts a DNS server it looks at a HOSTS file on your PC. If it finds the domain name and IP address there, it uses the IP address it finds. If it doesn't find the domain name and IP address, it goes out to a DNS server. Because your PC first looks to the HOSTS file for name resolution, you can use that file to block ads.
The HOSTS file is a plain-text file you can create or edit with a text editor like Notepad. The file has no extension; it is named only HOSTS. You'll find an existing HOSTS file in C:\Windows\System32\Drivers\Etc\HOSTS. (In Windows XP Professional, it is located in C:\Winnt\System32\Drivers\Etc\HOSTS).
Each line in the file consists of an IP address and a domain name, like this:
184.108.40.206 oreilly.com 216.92131.107 simtel.net
When you type in an address such as http://www.oreilly.com, your PC looks in the file, sees that its IP address is 220.127.116.11, and then sends you there.
Every HOSTS file also has one default entry:
127.0.0.1 is a special IP address called a loopback because it refers back to your local computer, not to the Internet or a network. It's used by developers to test network software without having to be being physically connected to a network. But you can also use the loopback address to prevent web ads from displaying.
To use the HOSTS file to block ads, you edit the file by adding individual entries for each ad server, and then associating those entries with the loopback addressyour own computer. So, when you visit a site with ads, your PC looks at the HOSTS file, finds the entry for the ad server, but never visits the ad server because it's instead redirected to the loopback address. So, the ads are never displayed, and your travels aren't tracked.
For each ad server you find, create a line in your HOSTS file, like this:
Double-click is one of the largest ad servers on the Internet, so this entry will block a significant number of ads.
How to find ad servers? In your browser, right-click an ad and select Copy Shortcut. That'll put the ad's URL into the Windows Clipboard. Then you can paste it into your HOSTS file. Make sure to include only the domain name portion. So, for example, when you right-click an ad and copy its location, you might get a very long entry, like this:
http://ar.atwola.com/link/93182535/html?badsc=B0Q0AoVXYvX-nBcuskw4IZTGAt -b7n1Q2V6vctHpvtzTK5RxgZIq9FU6ESe4QfJ7ELVJ3ENBHgvUkPknRBjhXGQIU32DP3fv_uj-LT3lA5W -A3k5mRc7pQl6QXJ6G9mgrNblbJDXkPLBNqQXvIwmZby-bDLeZvaX9kP33Xk0XAO5jQ -u5hUSd4k7tpzXK8soyJBOZQ3lNAt5qcj8tMoKpLG_tKza0JSChRrO8af31JSM5 -UX69B1BFEpSfUmp4ZfT5XLEI35bYTQoHS6tbTvZRcK7C8YjgqxdH
In your HOSTS file, though, use only the domain name. So, this would be your entry in the HOSTS file:
It can be almost impossible to compile a list of most of the ad servers on the Internet like this. And because the servers change constantly, you'd have to constantly try to keep it up-to-date. So, instead of trying to do it yourself, you can go to a web site that has a HOSTS file with hundreds of entries Go to http://everythingisnt.com/hosts, and you'll see a page filled with HOSTS entries for ad servers. Copy and paste it into your own HOSTS file. (For more information about HOSTS files and ad blocking, see http://www.everythingisnt.com/hosts.html.)
How well does it work? Take a look at before-and-after screenshots. Figure 4-27 shows a CNN page with no ad blocked; Figure 4-28 shows the same page with the banner ad blocked by a HOSTS file. Also note that the browser's built-in pop-up blocker blocked a pop up.
Figure 4-27. A normal CNN page, with no ad blocking
Figure 4-28. A CNN page with ads blocked by the HOSTS file
4.12.2. Use Ad-Blocking Software
The HOSTS file does a good job of blocking ads, but it's far from perfect. If, for example, ads are being delivered from the same domain as the web page you're visiting, ads won't be blocked. Also, if the ad server is not on your HOSTS list, you won't be able to block it. Furthermore, the technique might not block some of the more obnoxious ads on the Internet, such as Flash-based animations.
You can buy ad-blocking software for more effective ad blocking, or download free ad-blocking software. But you might not need to buy or download extra software because your software might already include it. For example, if you use the for-pay version of the ZoneAlarm firewall [Hack #78], ad blocking is built in. To block ads, run ZoneAlarm, and click Privacy on the lefthand side of the screen. On the page that appears, in the Ad Blocking section, choose High to block all ads. Choose Medium to block most ads, but to allow banner and skyscraper ads (ads that take up the vertical column on the right side of a web page). You can also customize the types of ads to let through by clicking Custom and choosing which ads to block, and which to let through.
If you don't have ZoneAlarm, the following free and for-pay programs block ads to varying degrees:
4.12.3. Hacking the Hack
The worst ads of all might well be the ones you don't even realize are ads, but rather, are sponsored results in search engines that look much like regular results. But there is a way to filter out even these types of ads; you can use the Search Sanity feature in AdSubtract Pro.
When you use AdSubtract, Search Sanity isn't turned on by default. But it's easy to turn it on. Double-click the AdSubtract icon in the Windows system tray, choose Search Sanity, and check the boxes next to the search engines whose results you want to filter. Click OK, and sponsored results and ads will be banished. Figure 4-29 shows the normal Google search results; Figure 4-30 shows the Google page with the sponsored search results filtered out by AdSubtract.
Figure 4-29. Normal Google search results
Figure 4-30. Sponsored search results filtered out by AdSubtract
4.12.4. See Also