Install Pi-hole on Raspberry Pi 4
Pi-hole is a free ad blocker for your whole network. It runs on a Raspberry Pi and answers DNS lookups (the step that turns a name like example.com into an address) for every device in the house. When a device asks for a known advertising or tracking domain, Pi-hole doesn't answer with the real address, so the ad is never downloaded. That covers phones, smart TVs and apps, where a browser extension can't help.
This guide installs Pi-hole on a Raspberry Pi 4 running Raspberry Pi OS. The steps are the same on a Raspberry Pi 5, 3 or Zero 2 W. Allow about 30 minutes.
What you need
- A Raspberry Pi. A Raspberry Pi 4 of any memory size is more than enough: Pi-hole needs 512MB of RAM. A Raspberry Pi 5 or Raspberry Pi Zero 2 W works too.
- The right power supply: the 15W USB-C supply for a Raspberry Pi 4, or the 27W USB-C supply for a Raspberry Pi 5.
- A microSD card of 8GB or more. Our 32GB card comes with Raspberry Pi OS already on it.
- An Ethernet cable to your router. Wi-Fi works, but a DNS server is better on a cable.
- Optional: a case, since it will be running all day.
Step 1: Set up Raspberry Pi OS
Pi-hole supports Raspberry Pi OS, and the Lite version (no desktop) is all it needs. If you're writing your own card, use Raspberry Pi Imager, and in its settings set a username and password and turn on SSH so you can run the Pi without a screen. New to this? Start with Getting started with your Raspberry Pi and how to enable SSH.
Plug the Pi into your router, power it up, then open a terminal on the Pi (or connect over SSH) and update it:
sudo apt update
sudo apt full-upgrade -y
Step 2: Give the Pi a fixed IP address
Every device on your network will be told to send its DNS lookups to the Pi, so the Pi's address must not change. Find its current address:
hostname -I
The first address shown, something like 192.168.1.50, is the one you want. Then log in to your router and reserve that address for the Pi. Routers call this a DHCP reservation, static lease or address reservation.
Step 3: Run the installer
curl -sSL https://install.pi-hole.net | bash
The installer gives itself administrator rights (it may ask for your password), installs what it needs, then asks a few questions. Move with the arrow keys, tick options with the space bar and confirm with Enter.
- Static IP needed: a reminder of step 2. Continue.
- Interface: only asked if the Pi has more than one connection. Choose
eth0for the Ethernet cable orwlan0for Wi-Fi. - Upstream DNS provider: where Pi-hole sends the lookups it doesn't block. Any of the listed providers is fine; we chose Cloudflare.
- Blocklists: say yes to the suggested list (StevenBlack's Unified Hosts List). You can add more later.
- Query logging: yes, so you can see what is being looked up and blocked.
- Privacy mode: "Show everything" gives you the most useful dashboard on a home network. Choose a stricter level if others share the network and you'd rather not see which device looked up what.
Older guides also mention choosing IPv4 or IPv6 and installing a web server. Pi-hole 6 has its own web server built in and no longer asks.
Step 4: Note the admin address and set a password
The last screen shows the address of the web interface and a randomly generated password. Write the password down, or set your own:
sudo pihole setpassword
(This replaces pihole -a -p from Pi-hole 5 and earlier.) Then, on any computer on the same network, open http://pi.hole/admin or http://192.168.1.50/admin, using your Pi's address, and log in.
Step 5: Point your network at Pi-hole
Nothing is blocked until your devices use the Pi for DNS. There are three ways to do that; pick one.
- Change the DNS server on your router (best). In the router's DHCP or LAN settings, set the DNS server it hands out to the Pi's IP address, and leave any second DNS server blank so devices can't skip Pi-hole. Devices pick up the change the next time they reconnect.
- Let Pi-hole run DHCP. Some routers, including many supplied by internet providers, won't let you change the DNS server. Turn DHCP off on the router, then in Pi-hole go to Settings > DHCP, tick "DHCP server enabled", check the address range and router address, and save. Only one DHCP server should be running on a network.
- Set DNS on individual devices. Useful if only some devices should use Pi-hole. On a Mac: System Settings > Network, choose the connection, then Details > DNS. On Windows 11: Settings > Network & internet, choose Wi-Fi or Ethernet, then edit "DNS server assignment". Enter the Pi's IP address as the only DNS server.
Step 6: Check that it works
Reconnect a device to the network (turn its Wi-Fi off and on) and browse a few sites. On the Pi-hole dashboard, "Total queries" and "Queries blocked" should start climbing. You can also ask Pi-hole directly from any computer, using your Pi's address:
nslookup ad.doubleclick.net 192.168.1.50
A blocked domain comes back as 0.0.0.0.
Step 7: Allow or block a site yourself
If a site you use stops working, allow its domain; if something still gets through, deny it. In the web interface this is the Domains page. From the terminal:
pihole allow example.com
pihole deny ads.example.com
More blocklists can be added on the Lists page. After adding one, run pihole -g or choose Tools > Update Gravity to load it.
Keeping Pi-hole up to date
pihole -up
That updates Pi-hole itself; blocklists refresh on their own once a week. Keep Raspberry Pi OS current as well with the two apt commands from step 1.
More on Pi-hole
Parts for this guide
View all-
View product
Raspberry Pi
Raspberry Pi 4 Model B
$70.61 – $274.00In stock
-
View product
Raspberry Pi
Raspberry Pi Power Supply USB-C 5V 15W
$24.05In stock
-
View product
Pi Australia
32GB MicroSD card with latest Raspberry Pi OS
$49.45In stock
-
SaleView product
Raspberry Pi
Raspberry Pi 4 Case
$9.00 $14.18In stock
-
View product
Pi Australia
The Pi-Hole Smart Book
$31.80In stock