Down the Pi-hole
/I have a deep hatred for advertising, and advertising on the internet is basically the most insidious form of advertising. This is why for the longest time I have used browsers which support ad-blocking extensions (I recommend uBlock origin) but in early 2019 I came across Pi-hole, a network wide ad-blocking solution. In an attempt to get more people using it and reduce their exposure to advertising and therefore increase their quality of life, I thought I would document my Pi-hole journey.
What is Pi-hole?
Pi-hole is a network-wide ad-blocking solution. This means that rather than requiring that ad blocking be done at the device, or more often at the browser level, it is done at your point of connection to the outside world. More succinctly, it means that there will be a device on your network, normally a tiny computer, which stops the routing of advertising traffic to any page that you are visiting.
Pi-hole works by acting as a Domain Name Server (DNS). A DNS is a registry of addresses on the internet which is able to associate the addresses with their public Internet Protocol (IP) addresses. The reason for its existence is that is that it is much easier for us to remember names than strings of numbers, so the DNS acts as the go between for the names and numbers. As a general, the data for a website (the stuff you want) is stored on one server and the advertising content (the stuff you don’t want) is served on a different server. This means that when you are requesting data from one server and then another server wants to send you data, you can say no. Just imagine that you ask person A for something and then person B turns up and tries to give you something instead or alongside the goodies person A, you might not take them, especially if you know that person B has a history of giving away malicious gifts. This is exactly what Pi-hole does: it has a long and constantly curated naughty list and should traffic try to come from any of the naughty locations, it is simply blocked at the port of entry. This may sound like a simple idea, but it is immensely powerful: depending on which websites you visit and which devices you own, it is not uncommon to have between 40 and 50 percent of traffic blocked. And given the dire state of internet connections in Australia, this can have a significant effect on your bandwidth and network performance.
You are able to monitor in real time the requests passing though your network and see what has been blocked, from which domains and from what devices. I forget where I read it exactly (I am pretty sure it was on the Pi-hole subreddit) but it was quote on this topic saying
The great thing about Pi-hole is that you can see all the traffic on your network. The scary thing is that you see all the traffic on your network
which is particularly apt. After installing my own Pi-hole, it is incredible to see that some devices (notably a OnePlus mobile) try to “phone home” almost constantly, and clearly get angry that they are not allowed.
What do I need to produce a Pi-hole?
Pi-hole was initially designed to be run on a Raspberry Pi and hence the name. The Raspberry Pi is a single-board computer, designed to be extremely small, cheap, robust and low-cost with a goal of promoting basic computer literacy, especially in developing countries. Nowadays, they are used widely by anyone that wants to do almost anything with a computer, from home automation to research science, and are especially common at education institutions. And whilst Pi-hole was designed to run on one of these systems, it is not limited to them, only requiring a device that runs any of the supported operating systems. However, given the ease-of-use and the eloquence of Raspberry Pis, they are overwhelming the weapon of choice.
The shopping list for setting up you Pi-hole now looks as follows:
Raspberry Pi (in Australia)
I will add that you need things to power and interface with the Raspberry Pi, as by default it is sold by the board. There are kits available; however these tend to be overkill if you just want a Pi-hole. For reference, my shopping list was
I got the Raspberry Pi 3 as I expected I would do more than just run a Pi-hole and thus wanted a little more grunt than a Raspberry Pi Zero (which I ended up buying later) but also importantly, I wanted an onboard Ethernet connector. Raspberry Pis are powered over USB but can draw current than many standing UBS power adapters can output. I tried running my Pi on a 2.0 A adapter and experienced multiple failures, so it is worth getting a beefy adapter. A storage card is also necessary so you can load an operating system onto the device and run the Pi-hole software.
The only other thing that is required is access to the router of your network (and perhaps a bit of patience and a willingness to learn if you are not all that familiar with networking).
How to Pi-hole?
It is not my intention to provide an installation/setup guide, as there are countless ones already in existence. The official documentation gives a bare-bones overview, but I found these guides which took me from start to finish, and any unexpected issue has probably already appears in the reddit Pi-hole community. Just in case you are not sure whether to commit, I want to give you a flavour for the setup process so you can see that it is straightforward.
Put an operating system image for the Raspberry Pi on the SD card. This is done on any computer by downloading the distribution (I chose the desktop and recommend software distribution of Raspbain) and flashing this onto the SD card using etcher.io
Powering up the Pi with the SD card and installing the operating system, along with setting up your preferences for the Raspberry Pi.
Install Pi-hole. This is done using the command
$ curl -sSL https://install.pi-hole.net | bash
Configure your network settings in Pi-hole
Make the Pi-hole the DNS for your network. This is usually the only “tricky” bit as the process will vary depending on which router you have. However, most modern routers are very easy to configure and a search online of “<YOUR ROUTER> set DNS server” will likely provide detailed instructions.
Enjoy an ad-free browsing experience
It really is not a complicated process. If you are comfortable with networking, it will take an hour or so (mostly waiting for downloads and installations). If you are less comfortable with networking, perhaps set aside half a day. But as an added benefit, you will likely learn some networking!
My Pi-hole
Installation
My installation experience was pretty smooth, with only an error appearing during the Pi-hole installation:
Downloading and Installing FTL. Error: Unable to get latest release location from GitHub. FTL Engine not installed.
which others have experienced. My solution was simply to run the installer again
$ curl -sSL https://install.pi-hole.net | bash
which rectified the issue.
Updating
By default, Pi-hole does not automatically update. Despite the process of updating being very simple
$ pihole -up
I do not want to have to do this manually. It is very simple to automate this process, and that is exactly what I did. Using the cron utility, it is possible to schedule jobs, in this case weekly. The first step to to create a cron job. We begin by navigating to the relevant directory and creating a job which I have called autoupdate
$ cd /etc/cron.weekly $ sudo nano autoupdate
You should now be editing the autoupdate file in GNU nano. The update code is a simple bash script (or shell script) and is shown below
#!/bin/bash sudo apt-get update sudo apt-get upgrade -y sudo apt-get autoclean pihole -g -up pihole -up
This file should be saved and closed and the permissions must be modified using
$ sudo chmod +x autoupdate
Then everything is set. Once a week, you Pi and Pi-hole will update!
Future Pi-holes
The Pi-hole experiment was a major success, and I am keen to expand upon it. As mentioned, I purchased a Raspberry Pi Zero with the intention of using this in place of my 3 B+; however it is wireless only, and 2.4 GHz to boot, and given I only run a 5 GHz network, I will likely find other uses for the Zero. But other units, for example the one shown below (taken from this thread) look pretty neat, so who knows what the future holds.
The Pi-hole project
Pi-hole is free software which is supported by donations. If you found this guide useful or enjoy the fruit borne by Pi-hole, please consider donating to the developers. Moreover, consider donating to any free websites or software that you use regularly or think are worthwhile; it is important to consider than as much as it sucks (and it really does suck), many sites rely on advertising dollars to stay afloat, and by using ad blocking technology we are starving them of this avenue stream. I like quality content, which is often produced by independent creators, and I don’t want the sources of that content nor the content itself to disappear. I therefore have a responsibility to support quality content, and consequently I do support what I think is quality content and hopefully you do too.