Stop Ads with Pi-hole

Pi-hole is a DNS that intercepts DNS requests and blocks any request it deems is for an ad. This allows you to implement network wide ad-blocking across all devices, e.g. mobile phones, laptops, tablets, smart-tvs, etc.

In this guide we will setup a Pi-hole server on a Raspberry Pi. Luckily this is super simple.

Components

We will need:

Optionally you can put your Raspberry Pi in a funky case, mine is in a Rainbow Pibow Case

Flash the SD card

We will use Raspberry Pi OS as the base image as the Raspberry Pi guys have gone to the effort of creating it for us.

Flashing an Micro SD Card using Balena Etcher Creating ssh file in boot drive

Boot it up

Work out the IP address and reserve it on my router

The Raspberry Pi you started should be resolvable at raspberrypi.local. I use ping to resolve this to the IP address on my local network.

ping raspberrypi.local
# PING raspberrypi.local (192.168.86.39): 56 data bytes
# 64 bytes from 192.168.86.39: icmp_seq=0 ttl=64 time=1.326 ms
# ...

I am also taking the opportunity to reserve static IP addresses on my router the Raspberry Pi. This just makes it easier in the future. I am using the IP 192.168.86.254. For the new IP address to be adopted I need to restart the device. Now when I ping it I get the static IP address.

ping raspberrypi.local
# PING raspberrypi.local (192.168.86.254): 56 data bytes
# 64 bytes from 192.168.86.254: icmp_seq=0 ttl=64 time=1.237 ms
# ...

SSH in to the Raspberry Pi and perform initial setup

SSH in to the server as the pi user. The password will be raspberry, don’t worry we will be changing this.

Once logged on run

sudo raspi-config

This will bring up the Configuration GUI. There are a few things we need to do here:

Choosing finish will reboot your Raspberry Pi and set the configuration.

Add your SSH key

Passwords are rubbish. We will be authenticating with our Raspberry Pis using SSH keys instead. If you don’t already have one they are easy to generate.

To check if you have one already try out

ls ~/.ssh/id_rsa.pub

If you don’t have an SSH key already you can use ssh-keygen to create your own.

Now copy the SSH key to the Raspberry Pi. I am using the new hostname here.

ssh-copy-id [email protected]

Now when you SSH on to the server you won’t be asked for a password. You will be authenticating using your SSH keys.

Install Pi-hole

This is super simple, just run curl -sSL https://install.pi-hole.net | bash.

After performing some package installation steps you should be presented with this install window.

Pi-hole installer - introduction window

Progressing through the installation steps the next window of note is choosing the upstream DNS provider. This will be the DNS provider that the Pi-hole will forward non-blocked requests to. I have chosen the Google DNS provider, but you can choose whichever you wish.

Pi-hole installer - upstream DNS choice

The next step of note is where we can specify which lists are used to block DNS requests. I will stick with the default.

Pi-hole installer - block lists

Next we can choose to support IPv4, IPv6 or both. I leave this as the default, both.

Pi-hole installer - ipv4, ipv6 support

Since we previously configured the static IP address for our Rasbperry Pi the next step is a confirmation step. If you haven’t yet configured the static IP you can change it now.

Pi-hole installer - static IP address

The next few steps I leave at the defaults, to install the web interface, a web server, to log queries and to store and display all details.

Pi-hole installer - admin interface Pi-hole installer - web server Pi-hole installer - log queries Pi-hole installer - privacy level

Finally you will be presented with the installation complete screen. This screen provides you with confirmation of the IPv4 and IPv6 addresses that the Pi-hole instance is hosted on, a link to the instance and the password to access the main part of the web interface.

Pi-hole installer - installation complete

Use the IP address or the .local hostname you previously configured to access the web interface. In my case this was http://pihole.local/admin. You should be presented with

Pi-hole web dashboard

Configure Pi-hole as the network DNS

The Pi-hole is up and running, but we need to configure our network to use it. You can either do this on every device :(, or once on your router. We will choose the latter, configuring the DNS on your router will mean every device on your network will use the Pi-hole. I use a Google Nest Wifi Router so I just need to enter the Pi-hole’s IP address as the DNS in the App.

Google Wifi DNS Configuration

Enjoy Ad-less internet

Time to try it out. One website we are all familiar with is Speedtest. Here is the before that we all recognize, with five ads:

Speedtest.net before Pi-hole

Using Pi-hole we now have a rather sparse interface.

Speedtest.net after Pi-hole

I think we can all agree that it was worth it. Not a lot of work for an ad-free experience!

Comments

comments powered by Disqus