Ad-Free Network with Pi-hole

This is a tutorial for installing Pi-hole on your home network. As the devs on the pi-hole.net put it, it is a “network-wide ad blocking” solution. The app acts as a DNS (domain name system) server. More info on this wiki. It basically sends ad queries that you generate when you visit a website to nowhere (hence the cosmic flavor of the app name).

Ingredients

A few elements are needed for the setup. In this tutorial, I will use a pi zero computer, but the setup can be done on a slew of devices and there is also a docker install.

What I used (from left to right):

Devices used for Pi-hole setup
Pi-hole ingredients
  • micro USB to USB stick adaptor
  • mini HDMI to HDMI adaptor – not used, as I performed a headless installation
  • Micro USB B to USB A adaptor
  • USB 2.0 and Ethernet hub – used for the Ethernet port as I installed it wired
  • Official Raspberry Pi Zero Case with 16 GB micro SD card on top
  • Raspberry Pi Zero WH
  • USB 2.0 to micro USB from an old Chromecast for power

I spent about 60 quid on PiHut for the Pi Zero Started kit and the USB to Ethernet hub, the rest of the stuff I had around the house.

Pi OS installation

For our use, a very small OS for the pi should be more than enough. It is advised to use the pi device for the pi-hole installation exclusively.

The first order of business is to download and install the raspberry pi imager from raspberrypi.org.

Raspberry Pi imager download
Imager download

The app will prepare and install the OS on your SD card. Attach the SD with the adaptor to your main computer and let the imager do its magic. Once you choose your SD card and OS, it will download and install everything.

Raspberry Pi imager window
RPi imager
Raspberry Pi imager OS options
I used is Raspberry Pi OS Lite.
Raspberry pi imager SD card format notice
SD card format notice
Raspberry pi imager sucessful write operation
Success

To connect to the pi later, create an ssh.txt file on the boot partition of the SD card.

Create ssh tect file
ssh file location in linux

Once prepared, insert the card into the Pi device, power it up and attach it with an Ethernet cable to your router. I have an extra USB port on the router which I use for powering up the little pi.

Reserve the Pi’s ip on the home router

This is somehow variable depending on the home router manufacturer. Once you log on to the router administration page, on the DHCP settings page of your router, you should see all connected devices, both the LAN and the wireless ones. Look for the device called rapsberrypi and note the ip and MAC address. Now look for a setting called DHCP reservation, or in my case is called DHCP binding, that will allow you to set the ip of your raspberry device as reserved or static. This is necessary because the pi will function as a DHCP server that needs a static ip. For more information, check out this tutorial from howtogeek.

Home router DHCP settings
This is how it looks on my router

Once I added the ip and the MAC address, the lease time of the DHCP provided ip changed from about 84000 seconds to infinity.

Install Pi-hole

The OS installed on the pi has a text-based user interface, so we will connect to it by secure shell or ssh. More info on this wiki. SSH is very convenient as the pi does not need a user interface for the pi-hole, and we will rarely need to configure the pi. For the pi-hole configuration, we can use a nifty web interface, as we will see.

The ssh connection app depends on your computer main OS. For windows, you can use Putty, a handy terminal emulator. For Linux/Mac, the default terminal is more than adequate.

Putty start screen
Putty

In putty, use the pi’s ip address as the hostname, in my case 192.168.1.104 and raspberry as the password.

Putty connected to the pi screen
Putty connected to the pi

On Linux/Mac, open a terminal and type ssh pi@pi’s ip address or in my case:

ssh pi@192.168.1.104

Type the password as above.

From now on, the commands and the screens are the same on all OSes, so let’s soldier on:

wget -O basic-install.sh https://install.pi-hole.net

Once the script is downloaded type:

sudo bash basic-install.sh

Now the install turns into a classic old-school GUI setup:

pi-hole install screen 1
Intro
pi-hole installation donation page
If you like it, why not contribute
Done this in the router configuration
pi-hole installation network internet selection
Choose eht0 (Ethernet 0) here for wired
pi-hole installation DNS provider
I selected Cloudfare as it does not collect any info
pi-hole installation ad list
Ad lists contain known ad domains. The default list is perfect for now.
pi-hole installation select ip protocols
Default is fine
pi-hole installation ip conflict notice
We already configured the router

You might get an IPv6 confirmation screen for your ipv6 address. Just ok it. I skipped the image as it contained my ipv6 address.

pi-hole installation web interface options
I left on as the interface is very useful
pi-hole installation web server option
Needed for the web interface
Not really needed. Turn off to protect the SD card extensive rewriting.

If this is left on, it will reduce the life of your SD card. One option is to use log2ram, a script that enables saving of all logs on the ram instead of the SD card. If left on, the option can easily be disabled in the web interface settings. Just look for the disable query logging option.

Faster Than Light DNS services provided by Pi-hole. I left it at default.
pi-hole installation confirmation screen
Congratulations. Pi-hole is installed.

Replace “password” with whatever is displayed on your screen. Please make a note of it because you will need it for the web interface configuration login.

Post-installation

Now that the pi acts as your DNS server, you need to let your home router in on that too. This needs another visit to the router configuration page. Just type the ip of the pi device as DNS server. In my case, this is in Network > LAN > DHCP Server > DNS Server 1 IP Address.

Now restart your pi and the rest of the devices connected, and Bob’s your uncle.

Another option would be to leave the DNS unchanged on the router and only change it on the devices you want your ads blocked by the pi-hole. This is slightly more involved and is different depending on the device, but it might be useful if someone else in the household is experiencing difficulties with your stringent ad diet.

Web interface after some browsing should look as below. To login for more information and setting changes, use the info on the last page of the installation screen.

pi-hole web interface
Web interface

Of note, the pi-hole won’t block ads on websites that offer ads on their own pages, i.e. Youtube or Facebook, because the ad and the content domain are the same. Also, some ads are beneficial for sustaining some small websites and content creators, so please consider whitelisting ads on websites you want to endorse.

Hopefully this tutorial proves useful for installing Pi-hole on your home network. I certainly learned a whole lot by writing it.

Useful links: