Lightweight ad-blocking with dnsmasq and Raspberry Pi

Alex Ellis
11 min readAug 7, 2020

Did you know that you can put that spare Raspberry Pi of yours to work as a caching DNS server and ad-blocker using off-the-shelf packages for Linux?

Stop adverts and the privacy invasion caused by behavioural trackers

Now, first of all let’s get something out of the way. Many of us will be aware of the open source project written in PHP called “PiHole.” PiHole automates dnsmasq and adds a UI dashboard on top, so that you can geek out over the how many adverts you may have blocked.

It’s not that there’s anything against PiHole, but dnsmasq is quite capable on its own, and designed to be so light-weight, it is shipped with all Android phones by default.

So why would we want to deal with dnsmasq, if PiHole is so great? Well, first of all, it means running PHP, a webserver, and a database on your poor little Raspberry Pi, and these are all unnecessary for the task of blocking ads. It also means that many users have little to no understanding of what PiHole is actually doing under the hood.

In this post I’ll show you what dnsmasq can do on its own. We will setup a Raspberry Pi as a caching DNS server, and then show how it can also be used with a block-list of domains, and finally, how you can get all of your devices on your home-network to use it.

Overview

--

--