Quantcast

Hacking and Tech Mischief: Superior Ad Blocking on OS X

Get the WebProNews Newsletter:


[ Technology]

I love surfing the web. I have DSL and I get pretty good download speeds (compared to 56K modems, insane download speeds). Even though I have a good connection, I still hate downloading obtrusive ads. You know those huge “skyscraper” ads, or those pesky Flash ads that seem to take forever to download?

Even more annoying are the pop-up ads that show up on a surprising amount of sites considering everyone hates them with a passion (except evil marketing types). I’m about to show you how to block almost all of the aforementioned ads in ANY browser in OS X. If you don’t want to be bothered with pop-ups use a program or browser that disables them. My method only stops the ads from loading, not the window from popping. Chimera has a killer pop-up blocker installed by default (haven’t seen one so far).

Some people may say that it isn’t right to block ads… That’s how sites stay free. That’s true, and that’s exactly why I’m only giving directions to block the big boys that have no concern at all for your privacy (can we say doubleclick?). This will not block ads on MacMerc, MacMinute, MacUpdate or any other well run site. My goal by blocking ads is to speed up surfing. Only graphical ads are blocked… Text ads are let through. If you really like a site and you’re afraid that they will lose income when you block its ads, look around on that site and most likely there are other ways you can support it. Most webmasters would rather all their visitors gave $10 a year than have to run ads. I know MacMerc would :P. If you can’t find anything just email someone there and ask where you can send a donation. It will be appreciated.

The following is a list of the “Big Boys” in the adserving market that many sites use to outsource ads:

doubleclick.net
linkexchange.com
adsmart.net
admonitor.net
msn.com (not an outsource service but gobs of ads come out of ads.msn.com)
smartclicks.com
focalink.com
bravenet.com
bfast.com
sextracker.com (You’d be surprised)
hitbox.com
valueclick.com
fastclick.net
realmedia.com (these ads are hugely huge)

And there are several more. If you do a lot of “source hunting” you’ll soon notice that 90% of ads come from less than 100 locations.. Should be easy to block right? Well, in OS X it’s a piece of cake.

Open the terminal by going to /Applications/Utilities/ and opening Terminal. You may not have ever used the Terminal before but do not worry, this won’t be hard. Type:

sudo pico /private/etc/hosts

When prompted, enter in your administrator password (if you’re the only user of your computer, it’s just your regular password). When you type nothing will appear on screen (not even *’s). This is a security mechanism. When you finish your password just press enter. You’ll be taken to a screen that should look something like below:

Pico is a simple text editor for Unix. It’s commands are a little funny for Mac users since it uses control instead of command, but it’s otherwise really easy to learn. The ^ key signifies control for any interested souls out there :P. What this file does is associate hosts. The first line means when a request for localhost comes in send it to 127.0.0.1 (almost the universal address for the local-computer). What we’re going to do is insert some well known ad servers into the right hand column, and send them to 127.0.0.1 in the left hand column. For extra points we’re going to set up a custom 404 error page to keep blocked ads looking pretty. Here is a list I compiled of the most popular/annoying ad servers along with the 127.0.0.1 forwarding address. Copy and paste this list into pico (select the text and press Control-C, in pico use the arrow keys to highlight an area below the last line with text on it and press command-v). Once you successfully copied the addresses press Control-o and hit enter once you see the message asking for a file name. Then hit Control-x. Keep the terminal open for the 404 message step (not a real message that shows in the Terminal, but you need to keep it open for the step that prevents nasty errors to be shown).

Now you need to turn on your personal web server. If you don’t, you’ll have to click through warning messages about every 2 seconds for most every page you visit. To do so just open up the System Preferences by going to the Apple Menu and choosing “System Prefrences…”. Once the preference pane opens, choose Sharing. In the sharing pane, check the persona web sharing box. The pane should look like this before you click the check box:

If you were to restart your computer now, and started browsing the web, you’d notice a lot fewer ads. But, you’d also notice really weird looking error messages. Here’s a picture I took of my browser at Tucows.com:

I think having the ads in place might look better… But the load times without them are much nicer. To fix this, we’re going to make a custom error message. All that text means is that the ads can’t be found on your computer… Of course they can’t… We’re trying to get rid of them! Get back in the Terminal and type:

sudo pico /etc/httpd/httpd.conf

You’ll be greeted with the now familiar Pico interface but now with a lot more text. No worries, this is a down and dirty task. Press Control-w and type (or paste):

ErrorDocument

Look for the following text:
# ErrorDocument 404 /missing.html

Move your cursor with the arrow keys until it’s one character to the right of the #. Hit delete. This “un-comments” the line. We’re telling Apache that when there is a missing page, use missing.html instead of the error message. If you run a web server (like I do) you can get more tricky and throw it to a script that dynamically decides if you’re trying to block an ad or if someone found a broken link on your web server (I’ll save that for part 2). To save this file hit control-o and then control-X. You can close the Terminal. Now just download this file and place it in /Library/Webserver/Documents/.

Go ahead and restart your computer. When you next start your web browser, head over to a large site like CNN or TuCows and notice the difference. I’d suggest using Chimera to get the best effect… no pop windows and no large obtrusive ads. If you go back to TuCows you’ll see a nice ad free version like this:

Jon Gales is a PHP consultant and internet publisher. He writes
Macintosh slanted content for both MacMerc.com and MacDesignOnline.com.
Jon publishes both MobileTracker.net and NewsIsCrappy.com.

Hacking and Tech Mischief: Superior Ad Blocking on OS X


Top Rated White Papers and Resources
  • Guest

    Yes- I use ad block so you won’t get any revenue from this page and you won’t get any money from me for writing crappy articles like this. Awesome!

  • Join for Access to Our Exclusive Web Tools
  • Sidebar Top
  • Sidebar Middle
  • Sign Up For The Free Newsletter
  • Sidebar Bottom