Written in July 2021. Some commands, package names and versions here may be out of date.
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.
Updated 27 Nov 2026: this guide is a 2021 snapshot, written against the May 2021 Raspberry Pi OS (buster) image. Since April 2022, new Raspberry Pi OS images have no default pi / raspberry login: you create a user at first boot, or set one up in Raspberry Pi Imager. The secondary DNS section no longer says a second server is only a failover that rarely lets ads through: which server a device asks is up to the device.
Prerequisites
- Raspberry Pi 3 or newer
- An SD card
- Access to your router’s DHCP settings (to change the DNS server)
- Some time
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:
- Windows: Download here
- Linux (Debian/Ubuntu):
sudo apt update && sudo apt install rpi-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
If the Pi is your only DNS server and it goes down, devices that get their DNS server from the router can’t look up names. A second DNS server in the router’s settings gives devices somewhere else to ask. Anything that server answers isn’t filtered by Pi-hole, and which of the two servers a device asks is up to the device.
Popular options:
- Google:
8.8.8.8,8.8.4.4 - Cloudflare:
1.1.1.1,1.0.0.1 - OpenDNS:
208.67.222.222,208.67.220.220
Let me know if I missed anything.