Linux · July 24, 2021 · 3 min read

Install Pi-hole on Raspberry Pi

Network-wide ad blocking with a DNS sinkhole on Raspberry Pi. Setup, DHCP configuration, and secondary DNS failover.

Pi-hole is a DNS sinkhole. It blocks unwanted content across your entire network without needing to install anything on individual devices. In practice, that means network-wide ad blocking. Phones, smart TVs, IoT junk, all of it gets filtered. No client-side setup needed.

One thing to be clear about: Pi-hole won’t block YouTube ads. Those come from the same domains as the videos themselves. For that, a browser extension like uBlock Origin is your best bet.

Prerequisites

Prepare Pi for Install

Download the OS

Grab Raspberry Pi OS. The Lite version is fine for a headless setup.

Write the image to SD card

Unzip the download first. You’ll get an image file like 2021-05-07-raspios-buster-armhf-lite.img.

Do not flash the zip file directly.

GUI method (Linux/Windows)

Use the official Raspberry Pi Imager:

dd method (Linux)

sudo dd if=<Path to Image File> of=<Path to SD card> bs=4096 status=progress && sync
# e.g. sudo dd if=./2021-05-07-raspios-buster-armhf-lite.img of=/dev/sdb bs=4096 status=progress && sync

Boot and Update

Insert the SD card, plug in Ethernet, and power it on. It’ll resize the filesystem on first boot. You might need a monitor and keyboard if SSH isn’t enabled by default.

Login with the defaults (pi / raspberry) and update:

sudo apt-get update && sudo apt-get dist-upgrade

Reboot.

Install Pi-hole

Pi-hole has a one-line installer:

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

The installer will spit out a web GUI password at the end. Save it. You’ll need it.

Configure Pi-hole

The web interface runs on port 80 under /admin. Find your Pi’s IP:

ip addr

Then visit:

http://172.17.1.252/admin

Log in with the password from the installer. The default blocklists catch roughly 90% of ads out of the box. Tweak whatever settings you want, then reboot the Pi one last time.

Configure Your Router’s DHCP

Pi-hole can act as a DHCP server, but using your router’s built-in DHCP is usually cleaner. Go into your router’s settings and change the DNS server address to your Pi’s IP.

This step varies wildly between router models. Check your router’s manual. Set the Pi’s IP as the primary DNS server.

Secondary DNS

Pi-hole recommends being your only DNS server, but if the Pi dies your whole network goes down. Add a secondary DNS as a failover. A few ads might slip through when the failover kicks in, but it’s rare.

Popular options:

Let me know if I missed anything.

← All posts
Category: Linux