Pi-hole is a clever piece of software which acts as a network-wide ad blocker. It enables you to block ads on websites, ads in apps on your mobile devices and even on your smart TV, regardless of the software they’re running and without the need for any other local software on the device. Pi-hole also improves your network speed, because the ads are blocked before they are downloaded. This also saves data if you’re on a limited data plan.
A web interface lets you interact with your Pi-hole and view stats on your network traffic.
Now that you know what Pi-hole is, let’s have a look at how to to set one up on your home network, step by step.
If you’re running a large network with lots of users and traffic then the best device to use would be one of the Raspberry Pi 3 or 4 models with an ethernet connection to your router. But for a smaller home network with less than 50 devices and only a couple of users online at a time, a Pi Zero W works perfectly.
I’ve been using one for a month now.
Here’s a step by step video guide to setting up your Pi-hole, read on for the written guide:
What You Need To Make Your Own Pi-hole Ad Blocker
- Raspberry Pi Zero W Complete Kit – Buy Here
Alternately, buy the individual components:
- Raspberry Pi Zero W – Buy Here
- 32GD Micro SD Card – Buy Here
- Raspberry Pi Zero Case – Buy Here
- Power Supply – Buy Here
You’re going to need a Raspberry Pi Zero W, a micro SD card of at least 16GB, and something to put the Pi into to protect it, I just used the official case. You can usually buy these kits online for around $30-$50 dollars which includes everything you need, even a power supply, although you can buy the Pi alone for as little as $10 if you do some searching.
You won’t need a mouse, keyboard or monitor for this as we’ll be using another computer on the network to set up the Pi-hole.
Preparing Raspberry Pi OS Lite On The SD Card
We’ll start by preparing the Raspberry Pi’s operating system on the SD card, Pi-hole will then be installed to run on this operating system later.
Plug your microSD card into your computer. Don’t worry about formatting it just yet, we’ll get to that in a minute.
Start by downloading the Raspberry Pi Imager on your computer. This is a fairly new tool and it’s one of the easiest to use. They have a version for Windows, Mac and Linux.
You just select the Raspberry Pi operating system you need, which in our case is Raspberry Pi OS Lite, and then select the SD card you want to write the image to. Click write and let the tool do the rest, it’ll write the image, check it and then eject the SD card.
There is a bit more to do on the SD card before we’re done on the computer, so you’ll need to plug it in again to access it. You might get a couple of windows pop up and one which says you need to format the card in order to use it, just ignore these and close them. Don’t format the card again.
The will be one readable partition on the card called boot, you should be able to open this partition and you’ll see a number of files. We need to add two files to this directory, one to tell the Pi how to connect to your network and another to enable SSH so that you can access it over the network.
Download the network settings template wpa_supplicant and open it using a basic text editor like Wordpad.
In the network settings section, you need to add your local WiFi network name next to ssid and your network password next to psk, leaving all of the punctuation marks in place. You can also change your country code at the top if you’d like, this can be set up later though.
Save and close the file.
Now change the extension of the file from .txt to .conf. Click yes if you are given a warning.
Now copy this file into your boot directory.
Thats the first done, now we need to add an SSH file.
Create a new text file and change its name to ssh and remove the extension. So the file should just be a blank file called ssh with no extension.
Once you’ve got both of these files then you can eject and remove your SD card.
Plug the SD card into your Pi, then put it into it’s case and plug the power cable in. It’ll take a few seconds to boot up.
First Boot & Connecting To Your Pi Zero W
Finding Your Pi’s IP Address
Now that you’ve got your Pi booted up and (hopefully) running, you need to be able to access it in order to install Pi-hole onto it and make any settings changes or updates.
To do this, you first need to figure out your Pi’s IP address, which has been assigned by your router. There are many ways to do this, one of the easiest is by logging into your routers admin page. You’ll need to do this later anyway to make a few changes to your router’s settings. There are often details on how to login to the admin page, along with the default username and password, on the label on the router.
Depending on how complex your router’s software is, you may need to do some exploring until you find a page which lists all of the devices currently connected to the network along with their IP address, this is usually called a DHCP table. Take note the IP address assigned to your Pi.
While you’re logged in, you need to set this IP address (or another one if you’d like) up as a static IP address, so that your router always assigns this same address to your Pi-hole, this is an important step, you’ll see why in a bit. Again, all routers are a bit different, so you’ll need to do some digging if you don’t know how to set up a static IP on yours. If you can’t find the option, try googling your Router’s model and the words “static IP” and you should find some information.
You’ll typically need your Pi’s MAC address, which should also be listed in the DHCP table, and the IP address which you want to use. Enter these to assign your chosen IP address to your Pi each time it joins the network. If you choose a different one to the one currently assigned then you might have to reboot the Pi after this step.
Now that you’ve got your Pi’s IP address, you can access it over the network.
Connecting To Your Pi Over The Network
You’ll need to install a terminal emulator / SSH client like Putty to access your Pi’s terminal.
Enter your Pi’s IP address and then click open to attempt to connect to the Pi.
You’ll get to a black terminal display that asks you for a login. The default username is “pi” and the password is “raspberry”.
You’ll want to change these as soon as possible. So it’s a good idea to run the configuration tool first by entering:
This tool lets you change a number of settings on your Pi.
As a start, you should change:
- The default username
- The password
- Make sure that you’ve got the correct regional settings selected.
Installing Pi-hole On Your Raspberry Pi Zero W
Now you should have your Raspberry Pi Zero set up properly with a new username and password and connected to your network, with access to it over SSH.
Now you can install Pi-hole by entering the following command:
curl -sSL https://install.pi-hole.net | bash
The Pi will start downloading and installing the software. It takes a couple of minutes to run through and you’ll then get to the following page to guide you through the Pi-hole setup.
For the most part, you can just run through the default selected options and hit OK for each. You shouldn’t make any changes to these settings unless you know what you’re doing or you’ll likely just land up with a Pi-hole that doesn’t work.
You might want to change your Upstream DNS provider if you’d like. This is just the provider which your Pi-hole is going to use as the name server for your domain requests.
Also, make sure that the IP address listed is the one which you set as the static IP for your Pi.
It’ll then run through another setup process and you’ll finally get to an “installation complete” display. Take note of the Admin Webpage password as you’ll need this to log in to the Pi at a later stage to view the detailed statistics and to change any settings. You’ll be able to change this password from the web interface – but you need this password in order to do so.
You can change your Pi-hole password at a later stage over SSH using the command:
sudo pihole -a -p (new password)
You can now close the terminal connection.
Test if Pi-hole is running by going to your browser and typing in the IP address that you’ve configured for your Pi along with forward slash and admin.
You should see a page like this show up. You’ll notice that no queries have been received or blocked yet because the router isn’t directing traffic through the Pi-hole, there is still one last thing to set up.
Setting Up Your Router To Direct DNS Requests Through Your Pi-hole
You’ll need to log back into your router and find your DNS settings page.
Here you’ll need to set your Pi-hole’s IP address as the primary DNS server, if your router has to have a secondary DNS server, then type the same address into that field as well. Click save or apply to make the changes. You may then need to reboot your network devices to take effect.
If you go back to your Pi-hole dashboard, you should now see requests coming through and ads queries being blocked.
If you log in to your Pi-hole using the admin password that was created during setup, you should have more access to the network statistics and see detailed logs.
You’ll also be able to change settings, add or remove domains on the block list, and reboot or turn off your Pi.
Remember that if you turn off your Pi and your router’s primary and secondary DNS server are set to your Pi’s address, you will no longer have access to the internet until your Pi is back online. So make sure that your Pi-hole is on a reliable power source, preferably the same one as your router.
Some routers have a USB port on them which has enough power to supply an external drive. This port usually supplies enough power to drive a Raspberry Pi Zero W running as a Pi-hole, so you can ensure that they’re always on together.
This guide is just a starting point to get your Pi-hole up and running, there is a lot more than can be done using Pi-hole once you’re comfortable with it.
You can also set the Pi up to run the DHCP service, which allows the Pi-hole to identify devices by their name rather than IP address and even integrate powerful third-party anti-malware and anti-phishing DNS services.
That’s it, you’ll now be able to enjoy an ad free browsing experience on your home network!
Its worth noting that there are some limitations to the ad blocking ability of the Pi-hole. The Pi-hole is simply blocking requests being made to domains which are known to serve ad content, if the website you are accessing serves its own ad content, from their same domain, then the Pi-hole won’t block these ads. Typical examples are ads running on Youtube videos or Facebook ads in your Facebook news feed.
Let me know if you’ve used a Pi-hole in the comments section.