After being impressed with the ad blocking functionality of my F-Secure Sense I came across a popular piece of software called Pi-hole that acts as your homes DNS server and blocks advertising requests. It is designed to run on most Debian-based distro’s and it is specifically lightweight enough to run on a Raspberry Pi, some people have it running on a Pi Zero but I opted to use the more powerful RPi3 which I had spare.
Pi-hole works as a middle man between your DNS requests with servers such as Google or OpenDNS. So all your traffic will pass through Pi-Hole this passes the requests onto Google, and receives them back, it will then filter out advertising and tracking domains based on a blacklist it manages. Similar to AdBlock you can add as many black lists as you like and also whitelist domains. I started off with around 112k domains blacklisted, but after importing some recommended lists I ended up with around 600k.
Getting the server set up is really quite simple.
The official software support is:
- Raspbian: Jessie (lite / with pixel)
- Ubuntu: 14.04 / 16.04 / 16.10
- Fedora: 24 / 25
- Debian: 8.6
- CentOS: 7.2.1511 / 7.3.1611
I opted to try out DietPi which is a lightweight version of Jessie.
If you have ever use LibreElec or installed any other OS on a Pi, you will be familiar with the process, it is extremely easy. In this case, I just downloaded the image, then burned it to my microSD card using Etcher, inserted it into the RPi and away you go.
I was hoping I could just connect via SSH immediately, and maybe you can, but I couldn’t. So, I had to connect to a monitor for the time being. You will also want to plug into ethernet.
While the installation is very straight forward it takes a very long time for the installation to happen, certainly compared to getting LibreElec up and running. Once the initial install is done you will be greeted with a basic options screen where you can set up network setting and also go through the options selecting what software you want to install. There is a huge amount of services you can run, but I wanted to keep it as lightweight as possible and just installed Pi-hole.
One thing you should do during the install is set up a static IP. You will need to point your routers DNS to this, or each individual device and therefore the address needs to stay the same.
The Pi-hole installation also takes a long time but once done you should be able to access the web management via its IP address then /piehole.
From here you can see all the stats about blocked requests, manage your black and white lists, set up DHCP and various other options.
A couple of other tips from mistakes I made:
- Pi-Hole uses Lighttpd and needs port 80 for the web management if your run Apache for websites then you will run into issues. It can be fixed by messing around with the ports but it is easier just to have Pi-hole on its own RPI3 (I tried installing it on my main home server)
- Use the installer in DietPi – I used the curl command provided by Pi-hole initially and had problems getting it to work, I ended up doing a full reinstall and it worked straight away with the installer.
Once everything is running your browsing experience shouldn’t be negatively impacted, everything should work fine but with a lot fewer adverts. There are some domains that are worth whitelisting though and I used this thread.
If you have set your router up to use Pi-hole this means every device that connects to your Wi-Fi will also use this. Therefore, when in my own network all my mobile traffic is also passed through this which is exactly what I wanted. In theory, you don’t need extensions such as AdBlock anymore as Pi-hole should do the job for you, and in fact, I have found Pi-hole better as some website detect AdBlock and nag you, while Pi-hole seems to bypass some of these nags.
The RPi is small enough to be tucked away anywhere, I currently have it plugged into my router then powered on via the router USB. There are all sorts of cases and enclosures for the Raspberry Pi so you can easily locate it wherever you want
Overall, this was a fun little project, and for the cost of an RPi it is well worth doing in any home and it doesn’t require too much technical skills either.