Richard Sprague

My personal website

Super-easy ad blocking

Created: 2020-01-09 ; Updated: 2020-01-09

Digital advertising these days is dominated by big networks of internet advertisers, content producers, and go-betweens that try to use any information possible to hone in on targeted ads that you’ll click, hopefully leading to some money for whoever is doing the selling. But in the internet world, those networks are made of IP addresses – everything on the internet has a unique identifier – and your computer can decide which IPs to let through and which to throw into the memory hole.

The easiest way to do this on Macintosh is to edit the \etc\hosts file, a plain text list of all the IP addresses that your computer needs to track. Non-programmers rarely need to worry about this file, but you can easily edit it to block all IP addresses that you’d rather not access – like virtually all ad networks.

From the Mac Finder, click SHIFT-COMMAND-G to open a dialog box asking you to open a specific folder. Type \etc^[on Mac Catalina, you’ll need to go to this folder instead: /private/etc/hosts] and it’ll take you to this folder:

This is where your computer’s hosts file is located. Now right-click on that file and open it with your favorite text-editing app (TextEdit is fine). You’ll see a bunch of IP addresses and names like this:

It’s a list of numbers (IP addresses) and site names. Essentially, this is a list that says “if you see a site with the name in the right column, substitute its IP address with the number in the left column”.

A programmer named Steven Black has painstakingly assembled a list of every known advertising and spam IP address, and you can download it here:

Find the line on that page that starts with

# Custom host records are listed here.

and then shift-copy everything from that line to the end of the file. It’s a huge, huge file so I would hit SHIFT-COMMAND-downarrow to select everything to the bottom.

Now copy that bunch of text back into the hosts file you opened a second ago.

Leaving alone whatever was at the top of your hosts file, just paste the new blob of text onto the end.

Save it. (Your OS will probably prompt you for your password – go ahead and enter it)

That’s it! Now every time you encounter a web site that wants to feed you an ad, instead of getting the IP address of the advertiser (or spammer), your browser will substitute the innocuous address, which leads nowhere. Your web page will think it just got an empty ad, and will continue to lay out the page as though everything were fine. Unlike an ad blocker, which is part of your browser and can be detected by the code on the web site, this way of re-directing IP addresses can’t be detected by the web page. As far as your browser and whatever page you’re displaying is concerned, you did access that ad. It’s not your fault that the ad happened to be empty.

As a bonus, your computer will use much less bandwidth because it can ignore all those ads, many of which are megabytes in size. A typical banner ad, especially if it has video, can be pretty big, but your hosts file will seamlessly give an answer that has zero bytes. Nada. As a result, you’ll find that web pages load more quickly as well, especially since sometimes those ad servers can get bogged down and respond slowly. Now you’ll just skip them entirely.

Not only that, but Steven Black’s host file contains zillions of IP addresess from known spammers and other nefarious internet sites. Your computer is now protected from ever needing to access them.

A few types of ads will still get through: YouTube for example, as well as anything that’s built into the site itself. I found that the hosts file includes some sites from Amazon that I’d not mind seeing: I was unable to click through a paid ad when shopping on Amazon, even though I was interested in the item. But when my browser refused me entry, I simply updated the hosts file to let that specific IP address through and all’s fine.

The internet’s advertising-supported business model will eventually be replaced or augmented by something else – subscriptions I hope – but until then, this is a super-easy and convenient way to surf unrestricted by ads, and get much faster results to boot.