Block ads on your devices using a Raspberry Pi Zero and Pi-Hole

Learn how to install pi-hole on your Raspberry Pi to block adverts on your whole network without installing ad-blockers

Block ads on your devices using a Raspberry Pi Zero and Pi-Hole

Adverts are annoying. They slow down your browsing experience, especially on older PCs and devices. Block adverts without using ad blocking software on all devices on your network using a Raspberry Pi Zero and Pi-Hole.

Prerequisites - What you'll need

  • A Raspberry Pi Zero
  • A Ethernet adapter (I don't recommend doing this wirelessly)
  • Recommended minimum 8GB SD card
Raspberry Pi zero and ethernet adapter
Block ads on all your devices with a Raspberry Pi Zero and Ethernet adapter

I chose a Ethernet adapter designed for a Chromecast as it powers the device too, meaning you won't need to worry about an extra USB cable to power it. You can by it from Amazon over here.

Step 1 - Install Raspberry Pi OS

For the installation, we're going to use the official Raspberry Pi imager. We're using this as it has a secret hidden options screen which will allow us to enable headless ssh on our Raspberry Pi.

Headless SSH will allow us to access the Raspberry PI via SSH from the first boot, meaning we don't need to connect up a keyboard and a mouse to enable it on the Raspberry Pi zero later.

Raspberry Pi imager

Choose 'Raspberry Pi OS (32-bit)' and select your SSD in storage. Before we hit the 'write' button, we need to access the advanced menu.

Access Raspberry Pi imager advanced menu on Windows or Linux

To access the advanced menu on Windows or Linux, press CTRL + SHIFT + X.

Access Raspberry Pi imager advanced menu on MacOS

To access the advanced menu on MacOS, press CMD + SHIFT + X.

Step 2 - Enable headless SSH on Raspberry Pi OS

There's a couple of things we need to configure from the advanced options in Raspberry Pi imager. These are:

  • Hostname
  • Enable SSH
  • Change SSH password
Advanced options Raspberry Pi imager

First, check the 'set hostname' option and change this to 'pihole'. Also check the 'enable SSH' option and change the password for the 'pi' user to one which you'll remember.

In my example, I'm using wired ethernet so we don't need to set up the Wi-Fi SSID and password before we boot. I strongly recommend that you don't use Pi Hole wirelessly. You can also configure Wi-Fi here if wired isn't an option.

Finally, click 'save' and then 'write' to write Raspberry Pi OS to your SD card. Once complete, insert the SD card into your Raspberry Pi, connect up the ethernet and power it on. Everything else from this point will be done from SSH.

Step 3 - Find your Raspberry Pi IP address

Before we begin the installation process, let's find the IP address of your Raspberry Pi zero. This can be done from your router's DHCP interface:

Take a note of the IP address. In my example, my IP address is 192.168.1.2 but this will vary from one network to another. If your router allows you to always assign the same IP address to the Raspberry Pi Zero, make sure you enable this.

Step 4 - Install Pi-Hole on your Raspberry Pi

Let's go ahead and SSH into our Raspberry Pi Zero and install Pi Hole. As we enabled headless ssh we can do this using the IP address we know our Raspberry Pi is using:

ssh [email protected]
Ensure you change the IP address to the one on your network

First, let's ensure we're all up-to-date before we start the installer:

sudo apt update -y && sudo apt upgrade -y

Let's go ahead and install Pi Hole:

curl -sSL https://install.pi-hole.net | bash

The installation process will begin, we need to set some configuration options along the way.

Pi hole installer
The Pi-Hole installer

Go through the installer until it starts asking you about which upstream DNS provider to choose. Personally, I choose OpenDNS, I've had good experience with them:

DNS selection

After this you will be asked for third party block lists, just go with the default here and continue to the next step. After this, you will be asked which protocols to protect. This is dependent on your router so go with the default. As a minimum IPv4 should be selected.

Next it will ask if you want to set your IP address to be static based on the assigned IP. Go ahead and accept this. Now it will ask you if you want to install the dashboard and HTTP server, accept all the defaults and continue with the installation.

The installer will now finish and that's Pi-Hole set up. Make a note of the password that it has assigned for your dashboard, you can change this later on. Next we need to configure your router to use Pi Hole as its DNS server.

Step 4 - Configure your router to use Pi-Hole as the DNS server

For Pi-Hole to work for your network, you need to configure your router to use your Raspberry Pi zero as your DNS server.

In the DHCP settings for your router, set the primary DNS to the IP address of your Raspberry Pi zero:

Configure your router

That's it. Your network will now use Pi-Hole as the DNS provider, which will block adverts from loading. You can configure Pi-Hole and set exceptions through the admin which can be accessed via the IP in your browser. So for example, my IP is 192.168.1.2 for Pi-Hole, so the admin can be accessed from http://192.168.1.2/admin.

Here's a typical ad-heady page without Pi-Hole enabled:

With Pi-Hole enabled:

Conclusion

That's it! Adds are now blocked network-wide. A Raspberry Pi Zero is more than powerful enough for this kind of application. Any questions or thoughts, add a comment below.