Skip to content
GEEKnodes

Raspberry Pi

Pi-hole on Raspberry Pi: Block Ads Across Your Whole Network

Install Pi-hole on a Raspberry Pi to block ads and trackers on all your devices: official install, router DNS settings, blocklists and troubleshooting.

Pi-hole is a DNS server that blocks ads and trackers for every device at home: phones, TV, console or computers, without installing anything on them. This guide explains how to install it on a Raspberry Pi with the official method and how to make your network use it.

In short

  • Pi-hole blocks at the DNS level: when a device asks for an ad domain, it gets an empty answer.
  • It needs a static IP and the router handing out its IP as the DNS server.
  • It installs with a single command and is managed from a web panel and the pihole command.

Based on the official Pi-hole documentation. If you want to understand DNS before starting, read how DNS works.

How Pi-hole works

Every time a web page loads an ad, your device first asks “what is the IP of ads.ejemplo.com?”. Pi-hole receives that question and:

  1. If the domain is on a blocklist, it answers with a null address and the ad is not downloaded.
  2. If it is not, it forwards the question to a public DNS (your choice) and returns the answer.
Pi-hole DNS flow: ad domains get 0.0.0.0 and the rest are forwarded to the upstream DNS
If the domain is listed, an empty answer; if not, it is forwarded to the upstream DNS.

Strengths and limits:

Blocks wellDoes not block well
Ads in apps and Smart TVsAds served from the same domain as content (for example, YouTube)
Trackers and telemetryContent already embedded in the page
Known malware domainsDevices using their own encrypted DNS

Requirements

According to the official documentation:

RequirementValue
RAM512 MB
Free space2 GB (4 GB recommended)
SystemRaspberry Pi OS, Debian, Ubuntu, Fedora, Alpine…
NetworkStatic IP (or DHCP reservation on the router)

Any current Raspberry Pi works, including the Zero 2 W. Preferably wired by Ethernet.

Ports used

PortUse
53 TCP/UDPDNS (required, no other DNS server may run on the Pi)
80 and 443 TCPWeb panel (if taken, use 8080 and 8443)
67 UDPDHCP, optional

Step 1: give the Raspberry Pi a static IP

Pi-hole must not change address: if it does, the whole network loses DNS. You have two options:

  • DHCP reservation on the router (recommended): bind the Pi’s MAC to an IP, for example 192.168.1.10.
  • Static IP on the Pi itself: explained in set a static IP on Raspberry Pi OS.

Step 2: install Pi-hole

Update the system and run the official installer:

sudo apt update && sudo apt full-upgrade -y
curl -sSL https://install.pi-hole.net | bash

The documentation itself admits that running a script with | bash is debatable because you do not read it first. Alternative: download it, review it and run it.

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

The wizard asks:

  1. Network interface (normally eth0).
  2. Upstream DNS: the server it forwards unblocked requests to, for example Cloudflare or Quad9.
  3. Blocklists: accept the default list.
  4. Web panel and query logging: leave it on.

Step 3: set the panel password

When it finishes, the installer shows a password. To change it:

pihole setpassword

The panel is at http://PI-IP/admin (for example http://192.168.1.10/admin).

Step 4: make the network use Pi-hole

Installing Pi-hole is not enough: devices have to ask it. The documentation proposes three methods, best to worst:

Log into the router and find the LAN or DHCP settings. Change the DNS server handed to clients to the Pi’s IP.

  • Set only Pi-hole’s IP. If you add a second public DNS, many devices will use it and bypass blocking.
  • Devices pick up the new DNS when they renew the connection. Disconnect and reconnect Wi-Fi, or restart them.

Careful: changing the DNS of the router’s WAN is not the same. That changes the DNS the router uses, not what it hands out.

Option B: Pi-hole as DHCP server

If the router will not let you change DNS (some ISP routers do this), Pi-hole can hand out IPs. Enable it under Settings → DHCP in the panel and disable the router’s DHCP first: two DHCP servers on one network cause conflicts.

Option C: manual DNS on each device

Last resort: set Pi-hole’s IP as DNS on each machine.

Step 5: check that it works

From any computer on the network:

nslookup doubleclick.net

If the server shown is the Pi’s IP and the address is 0.0.0.0, blocking works. You will see the query counter rise in the panel.

Manage lists

Lists are added under Lists in the panel. After adding one, update the database (gravity):

pihole -g

Tips:

  • More lists is not better. Many aggressive lists break websites and apps.
  • If a site stops working, check the Query Log, find the blocked domain and allow it.

Useful commands:

pihole status          # service status
pihole disable 5m      # disable for 5 minutes
pihole enable          # enable again
pihole allow ejemplo.com
pihole deny  rastreador.ejemplo.com
pihole tail            # follow queries live
pihole -up             # update Pi-hole
pihole repair          # reinstall keeping settings

Common problems

SymptomCause and fix
The query counter does not riseThe router still hands out another DNS. Check option A and reconnect devices
Ads still show on a phoneIt has Private DNS (Android) or encrypted DNS in the browser. Turn it off
The whole network loses internetThe Pi is off or changed IP. That is why DHCP reservation is advised
An app or site does not loadA needed domain is blocked. Find it in Query Log and use pihole allow
The installer fails on port 53Another DNS server is on the Pi. Stop it
Odd errors after updatingpihole repair

Frequently asked questions

Does it slow down browsing?

Not noticeably: Pi-hole also caches answers, so repeat queries are faster.

What if the Raspberry Pi turns off?

Devices cannot resolve names and it looks like there is no internet. If that is a problem, set up a second Pi-hole and hand it out as secondary DNS.

Accessibility preferences

Quick profiles

Text and reading

Text size
Default
Line height
Default
Letter spacing
Default
Word spacing
Default

Colour

Motion and orientation

Cursor