Contents

Setting up a Pi-Hole

NETWORK AD BLOCKER ON A RASPBERRY PI ZERO W

Updated on 2021-02-06

What is Pi-Hole? and how does it work?

Pi-hole is open-source software that acts as a DNS sinkhole to protect your devices from unwanted content, without the need for any client-side software like apps or browser plug-ins. PiHole blocks ads using blocklists which check against a database of known ad serving domains. This way, it blocks ads not only in browsers, but also mobile apps and smart TVs — and it makes your network faster!


What You Need to Make Your Own Pi-Hole Ad Blocker

Full Kit:

  • RaspberryPi Zero W Complete Kit – Here

Individual Components:

  • RaspberryPi Zero W – Buy Here
  • 32GD Micro SD Card – Buy Here

Configuring the RaspberryPi

Pi-Hole is most installed on a raspberrypi, here is the Prerequisites for reference.

Install Raspberry Pi OS

  1. Download the latest Raspberry Pi Imager here

    image

  2. Pick Operating System: Raspberry Pi OS (32-BIT)

    image

  3. Insert your microSD card in to the card reader on your computer.

  4. Click Write. Then when Imager is done, you will see

    image

  5. DO NOT FORMAT THE PARTITION, click ‘Cancel’.

    Format

  6. You should see a new boot SD card mounted on your computer.

Configure Raspberry Pi OS

Enable SSH Access

Create an empty file called ssh on the new partition “boot” of the microSD card.

  • Windows
    • In Windows, the easiest way to do this open Windows Explorer and navigate to the boot partition.
    • To do this right-click in the root of the folder, select New->Text File Document and then call it ssh (no .txt extension)
  • Mac OS or Linux
    • use the terminal to change the root of the boot partition,
    • and run touch ssh to create the file.

Add a wpa_supplicant.conf file to the boot partition.

image

  • Open up the wpa_supplicant.conf file and add the following script to it.
1
2
3
4
5
6
7
8
9
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
# PI Hole CONFIG START
network={
    ssid="Your-network-name"
    psk="Your-network-password"
}
# PI Hole CONFIG END
Note
The Wi-Fi name and password should be the same as your local Wi-Fi which your PC is connected to (make sure your PC and Raspberry Pi are in the same LAN).
  1. Unmount the SD card and insert it to your Raspberry Pi.

Connect RaspberryPi to the network

Plug in the raspberryPi, and connect it to the network then figure out the Raspberry PI newly assigned address by using a network Scanner Angry IP Scanner

Once you know the Raspberry Pi newly assigned IP address, test your connection in command line by running Ping command. Now you can SSH to your raspberry pi by using Putty, or windows terminal.

PuttyClient

The default username and password of Raspberry Pi:

  • Username : Pi
  • Password : Raspberry
    image
    Once you successfully log in, screen will look like:
    image
Recommended

run the following command sudo raspi-config and update the following:

  • Update the default password for Pi
  • Update hostname from raspberrypi

Configuring Pi-Hole on RaspberryPi

While still connected to Raspberry Pi, now run the Pi-Hole install command: curl -sSL https://install.pi-hole.net | bash

test

then the Pi-Hole installer screens will begin

test

Once the installer begins you will see something similar to (Select ‘yes’ for installing ‘Web Admin Interface’ and ‘log queries’):

test

Pi-hole needs a static IP to function properly

test

Ethernet is recommended here for reliability

test

Quad9 for Upstream DNS

test

Enabling 3rd party blocklist

test

Leave Protocols as default

test

Confirm the static IP configuration

test
test

Install Pi-hole web dashboard

test

Install lighttpd web server

test

It is recommended to enable the log queries

test

Show Everything

test

Installation is complete. Please note down the password displayed on this screen because this will be the password that we will use to login to the web dashboard.

test

Required
Update the web admin page by running pihole -a -p
Optional
After the installation is complete, run sudo reboot
Info
for Other pi hole commands, simply run pi-hole -h or checkout this page

Now the Pi-Hole is functional, you can try login in to the admin web portal

To access the Pi Hole admin web UI, navigate to http://[Pi-Hole device IP address]/admin/

test


Configuring Network-Wide AD Blocker Settings

  • Log into your internet gateway as an administrator.
  • Locate the DHP server setting page, and set the primary DNS server to be the IP address of your Pi-Hole you configured earlier.
  • Set the secondary DNS Serever to 1.1.1.1 (Cloudflare) or 8.8.8.8 (Google)
  • Save the setting on the router, and reboot all your devices and that’s it!

You’ve now got the basic Pi-Hole Ad Blocking enabled for your entire network!


Conclusion

At the end, Pi Hole is an easy to set up nifty piece of software which can simplify ad blocking and domain tracking. It comes with a cool dashboard providing different statistics of your network and the ads being blocked. So, it will be very convenient to manage as well. Certain sites might not display properly. Moreover, many websites featuring quality content rely on ads for revenue, so if you like a certain website, consider whitelisting them in your Pi Hole backend.