Setting Up A Pi-hole Network Ad Blocker On A Raspberry Pi Zero W

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.

Open Pi Hole From Any Device

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.

Raspberry Pi Zero W Pi-hole

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:

What You Need For Your Pi-hole Ad Blocker

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.

Insert Your SD Card For Image Flashing

Plug your microSD card into your computer. Don’t worry about formatting it just yet, we’ll get to that in a minute.

Raspberry Pi Image Flasher Utility

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.

Writing The Image To The SD Card

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.

PiOS Lite Boot Folder

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.

wpa supplicant txt file

Download the network settings template wpa_supplicant and open it using a basic text editor like Wordpad.

WPA Supplicant

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.

Changing file to conf

Now change the extension of the file from .txt to .conf. Click yes if you are given a warning.

Paste supplicant file

Now copy this file into your boot directory.

Thats the first done, now we need to add an SSH file.

Add 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.

Completed Files Required

Once you’ve got both of these files then you can eject and remove your SD card.

Insert The SD Card Into The Pi Zero W

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.

Power It 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.

Finding The Pi's IP Address

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.

Using Putty To Access Pi

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”.

Raspberry Pi Config

You’ll want to change these as soon as possible. So it’s a good idea to run the configuration tool first by entering:

sudo raspi-config
Raspberry Pi Config Utility

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.

Install Pi-hole

Now you can install Pi-hole by entering the following command:

curl -sSL https://install.pi-hole.net | bash
Running Through Pi-hole Installer

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.

Installation Settings

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.

Upstream DNS Provider

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.

Installation Complete

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.

Fresh Install Of Pi-hole

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.

192.168.20.14/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.

Set Up Pi-hole As DNS Server

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.

Open Pi-hole From Any Device

If you go back to your Pi-hole dashboard, you should now see requests coming through and ads queries being blocked.

Log Into Pi-hole

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.

Settings To Shut Down Pi-hole

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.

Raspberry Pi Zero W Pi-hole

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.

Michael Klements
Hi, my name is Michael and I started this blog in 2016 to share my DIY journey with you. I love tinkering with electronics, making, fixing, and building - I'm always looking for new projects and exciting DIY ideas. If you do too, grab a cup of coffee and settle in, I'm happy to have you here.

14 COMMENTS

  1. I have used Pihole a lot. But I have to redo one. Because my orange pi has experienced a failure.
    I had made an answer on quora also to use it.
    Thanks for this article. A possible addition is the use of additional blocklist. I have found it much less easy to implement on recent versions of pihole. But there are things on github that can make it easy.

  2. After reloading the OS a few times, on my windows 10 PC all I see is a “recovery” drive, not a “boot” drive- I put the SSH file and WPA supplicant file in there but it doesnt seem to log into my wifi. what might i be doing wrong here?

  3. Hi Micheal,
    I will be setting up the pi-hole network ad blocker this week. My router has 2 wifi bands with my devices spread amongst them. How do I configure the wpa_supplicant file to identify both the wifi bands?

    • Hi Nishanth,
      I haven’t worked with a dual-band router, but I wouldn’t imagine that this makes any difference to the Pi-hole. I would think that your Pi-hole would connect to your router using the 2.4Ghz band for its own communication, but as long as the DNS settings for your router point to the Pi-hole then the Pi-hole will work across both bands anyway. This works in the same way that the Pi-hole doesn’t need Ethernet to block ads on the Ethernet connected devices on your network.
      Hope this makes sense.

      • I don’t have a source, but my router has a different SSID for 2.4GHz and 5GHz. With just the 5GHz SSID my Pi Zero WH wasn’t able to connect to the network.

        It depends on the Raspberry Pi model.

        • As far as I’m aware, Raspberry Pi’s arent able to connect to 5Ghz networks without an external adaptor. This doesn’t really matter though, it’ll still block ads served on your 5Ghz network if it’s configured to be your routers DNS.

          • This varies. The Pi 4 does support 5GHz, although there was a firmware bug. I know there is a USB-hub/ethernet adaptor for the Pi Zero.

            I suppose it’s a Maker thing. Can we do it fancy?

  4. The one flaw I have found is where you mention changing the log-in name from “pi”. You can’t do that from “inside” the account you’re changing. Google and there are ways of doing it, but I am not sure about doing it on a headless Raspberry Pi.

  5. when trying to set the Pi-hole’s IP address as the primary DNS server i get a message that says DNS server address and LAN address cannot be on the same subnet. I have a smooth brain and have no idea what this is

    • We’re probably all using the 192.168.0.0 – 192.168.255.255 private address block, and apparently that can be split into subnets. The details are going to depend on your router. I use the addresses on the 192.168.1.0 subnet and I suppose I could put the pi-hole on 192.168.2.1 which could be specified as a subnet.

      It’s one of those very basic networking ideas which most of us don’t need to bother with. But you could put the manager’s computer on a different subnet to the computer they have in the warehouse to track stock, and set up different limits on what they can access.

      Don’t trust me on anything specific. That will depend on what you have, and some routers are not very capable. But if you’re getting that warning, it suggests your router might be able to be set up to fix it.

      • ur not actually supposed to get it on 192.168.2.1, any thing with 2 in that chain before the last number makes somne kind of error or so im toald

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest posts

Solar Powered Crypto Miner Using A Raspberry Pi

A common question I’ve seen across a number of my Raspberry Pi projects and videos is whether you can use a Raspberry Pi to...

Connect and Program An OLED Stats Display For Your Raspberry Pi

In this guide, I'll show you how to program a 128x64 I2C OLED stats display as a quick dashboard for your Raspberry Pi. I...

Bitcoin Ticker Using An ESP32 and OLED Display

Today we're going to be making a desktop Bitcoin ticker using an ESP32 development board and an OLED display. This one has been programmed...

Related posts

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!