We all do it, at least those of use with a technical background, we all make use of ad blockers. Easily installed as a browser extension, the ad blocker is the weapon of choice in keeping one’s browsing experience joyful and clutter free.
If this is the case, why did I take on this ad blocker project? The issue isn’t with the current browser based ad blocker extensions, it’s that internet browsing has changed. Today one is more likely to browse via an mobile device than your standard computer. With no ad-blockers on mobile devices, you’re once again bombarded with advertising while browsing or using an ad supported app.
While initially palatable, between larger screens (iPad) and the growth in mobile, the annoyance of advertising had reached that inflection point where I needed to do something about it. I needed to move beyond simple browser extensions to a system the covered my entire network. I needed “An AdBlocker Supreme”.
While on first blush a network-wide ad-blocker sounds like a big hammer for eliminating those annoying web ads on my iPad, it’s a perfect solution. By blocking ads as they entered the network, not only would I eliminate ads while browsing on my iPhone, it would take care of in-app ads. It was a promising idea, now I needed to find a solution.
An initial search turned up various solutions, including proxy servers and caching systems. The issue was that these systems all needed dedicated servers. Not wanting to buy another system to put in my basement, I filed this idea away hoping to return to it if I ever decided to spin up a local network gateway.
Then one day a headline on Lifehacker caught my eye — “Turn Your DD-WRT Enabled Router into a Whole House Ad Blocker”. Could this be it? Is this what I’m looking for? And what the heck is a DD-WRT? After a little further reading it was clear this was another server-based solution, however I wouldn’t need to spin up a new gateway server, I could use some existing hardware — I could use an old Linksys WRT54G WiFi router. This was it, this was the ad blocker I was looking for!
The plan for the creation of the ad blocker system for my network was relatively simple: build a server that acts as a network gateway and add software that “poisons” the DNS entries for ad serving domains. With this in place, when an ad is requested by a web page/app the request goes to your local server, not the ad server located somewhere on the net. This local server returns an empty image, effectively blocking ads on your network. Simple — I like simple.
The server is a networking device that was one of the most prolific WiFi devices in the 2000s – the Linksys WRT54. The trick to doing this is replacing the firmware on the router with a DD-WRT distribution (www.dd-wrt.com). DD-WRT is a immensely popular open source project that enables advanced network capabilities for simple consumer level networking devices like the WRT54G. Once DD-WRT is installed, it’s just a matter of installing the anti-ads pack and configuring your system.
After some research, the best detailed description I found for this project was on How-to Geek at this link. It’s what I followed and I won’t repeat the great step-by-step instructions they provide. However, I will highlight key areas that took a little more effort during the setup process.
The first step is the installation of DD-WRT. Actually, for me it was locating a WRT54G I could use for the project — the linksys cable modem/wifi hybrid dingus I have wasn’t supported by DD-WRT. Luckily my parents had one of the ubiquitous blue and black boxes laying in their basement.
Despite all the warnings about “bricking” your router, DD-WRT is fairly easy to install. First step is locating your device on the dd-wrt website using the excellent search form they provide here. Once you locate you model, the firmware image and installation instructions are provided.
The instructions for my devices were extremely detailed and referenced a variety of other sources and notes. I’d recommend reading the instructions several times until you’re comfortable with the procedure. While I think the instructions tend to be conservative, it’s worth taking the outlined approach and not bricking your system.
Once the new firmware is installed and running, it’s time to install the secret sauce of the project — it’s time to install the ad blocker.
The Ad Blocker
Like almost every other new system project, the first step is to enable SSH on the router – a true hacker isn’t happy until the have a shell on a system. This is done via a simple option on the Services page of the DD-WRT configuration panel.
The next step is to create a writable file system on the router – by default everything is readonly. This is where the ad-blocking software is installed. This is done by enabling JFFS (Journaling Flash File System) on the router. Located on the Administration tab of the DD-WRT control panel, you’ll want to enable JFFS2 and Clean JFFS2. Once these settings are saved, reboot the router to have them take effect. Once the router is back up, you can go back to this section in the control panel to see how much free space is available on the JFFS2 system.
Next we install the anti ads pack hosted on How-To Geek here. I unzipped the archive which gave me two key files: pixelserv disable_adds.sh. From there I copied these over to the router.
The article on How-To Geek gives a detailed description on doing this from a Windows box. I’m on a mac, so first I created a dns subdirectory on the router via my ssh session. Then I just used scp to copy these files to a location in the JFFS file system on the router.
One gotcha I encountered was the copied text files had carriage control/line-feed issues (the classic ^M issue). A simple tr command cleaned that up:
At this point the ad blocker software is in place and just needs to be enabled in DD-WRT. To do this you add the following command in the Adminstration>Commands>Command Shell section of the DD-WRT control panel:
Once entered, select the “Save Startup” button. If successful, this command will appear in the Startup section of the page. At this point your ad blocker is installed.
Before you reboot and enable the system, it’s worth noting that additional sites can be added using the DSNMasq option in DD-WRT. This is for those ad serving sites that seem to slip through the system you. The How-To Geek guide provides a great detail in doing this.
At this point reboot the router and on startup it will start blocking ads. Note: It might take a minute or two after the router starts since it must first download an ad block site list.
My WRT54G was a pretty old version, and as such memory was scarce. While I never encountered a problem, free memory would get pretty low at times, making my inner sysadmin nervous.
To minimize memory consumption, I used the recommendations found here
I found that making some adjustments to the IP filter settings I was able to reduce the overall system memory consumption. The settings I used:
Once up and running this ad blocking system surpassed all my expectations. All my devices on my network are almost completely ad-free. No ads on my iDevices when I browse and a surprising number of in-app ads are disabled. And I’ve also disabled the ad-blocking extensions on my desktop browsers — they’re no longer needed – ya!
And the best part of the system is that it’s maintenance free. The ad-blocker dutifully updates in ad block list every week or so and the router is stable. I’ve had it run for months with out an issue, only rebooting it when I’m doing other admin tasks – but this is out of habit, not need.
No ads on any of my devices, maintenance free operations and repurposing an outdated router made this a fun project with long lasting benefits. It truly produced An AdBlocker Supreme!