DNS & Domain Names

Pi-hole and Network-Wide Blocking

Learn how Pi-hole blocks ads and trackers for your whole network, what it needs, how to set it up and what it cannot block.

Key takeaways

  • Pi-hole blocks by domain name, so it covers every device that uses it as its DNS server.
  • It needs an always-on machine with a fixed IP address, and your whole network depends on it staying up.
  • Ads served from the same domain as the content cannot be blocked this way.
  • Keep the software and lists updated, secure the admin page and never expose its DNS service to the internet.

Pi-hole is free, open-source software that acts as the DNS server for your network and refuses to resolve names on its block lists. Because every device asks it for addresses, ads and trackers served from listed domains fail to load on phones, televisions and laptops without installing anything on them.

It runs on modest hardware such as a Raspberry Pi, a spare computer, a virtual machine or a container. Expect an afternoon for setup, a little maintenance afterward and some ads that get through anyway.

How it works

Your router normally tells devices which DNS server to use. You point that setting at the Pi-hole. When a device asks for a name, Pi-hole checks its database of blocked domains. Allowed names are forwarded to an upstream resolver that you choose, and the answers are cached. Blocked names get a dead-end reply, by default an unusable address such as 0.0.0.0, so the connection fails immediately.

Where Pi-hole sits in a home network
Pi-hole Answers every DNS question, blocking listed names. Admin dashboard Shows queries and manages allow and block rules. Upstream resolver Answers everything that is allowed. Block lists Downloaded collections of unwanted domains. Router Tells devices to use the Pi-hole for DNS. Phones and laptops Send lookups without any extra software. TVs and smart devices Get the same blocking, with no settings of their own. Pi-hole Answers every DNS question, blocking listed names. Router Tells devices to use the Pi-hole for DNS. Phones and laptops Send lookups without any extra software. TVs and smart devices Get the same blocking, with no settings of their own. Block lists Downloaded collections of unwanted domains. Upstream resolver Answers everything that is allowed. Admin dashboard Shows queries and manages allow and block rules.

It doesn't sit in the path of your web traffic. Only DNS questions pass through it, so it doesn't slow downloads or see page contents. It's one form of the approach described in DNS filtering.

What you need

  • An always-on host running a supported Linux system, or a container platform. A small single-board computer is plenty for a home.
  • A wired connection where possible, for reliability.
  • A fixed IP address for the host, set with a static configuration or a DHCP reservation.
  • Router access to change which DNS server devices receive.
  • Basic comfort with a terminal and the willingness to troubleshoot when a site breaks.

Check the project's documentation for supported operating systems and current requirements before buying anything.

Installing it

The project publishes an installer script and an official container image. Follow the instructions on its own documentation site, since steps change between releases. If you run an install script, download it from the official source and read it first, because it needs administrator rights.

During setup you'll typically choose an upstream resolver, accept or add block lists, decide how much query logging you want and set a password for the web interface. Public DNS resolvers helps with the upstream choice.

Some Linux distributions already run a local DNS service on port 53. If installation complains that the port is in use, identify what holds it.

sudo ss -lunp | grep ':53'

Pointing your network at it

There are two usual methods.

Change the router's DHCP DNS setting so it hands out the Pi-hole's address to devices. This is the preferred method, because the dashboard then sees each device separately. If you change only the router's own upstream DNS, queries may all appear to come from the router.

Let Pi-hole run DHCP. If your router won't let you set the DNS server, disable the router's DHCP service and enable it on the Pi-hole. Never run both on the same network without careful planning. DHCP explained shows what the service does.

Then renew leases by reconnecting devices, and confirm it's working.

# from any computer; replace with your Pi-hole's address
nslookup example.com 192.168.1.10
# on the Pi-hole host
pihole status

If your network uses IPv6, devices may also learn an IPv6 DNS server from the router. Configure it to advertise the Pi-hole's IPv6 address or stop advertising another, or some lookups will bypass your blocking.

Setting up network-wide blocking
1 Prepare the host Update the system and give it a fixed address. 2 Install Follow the project's current instructions. 3 Test one device Point a single computer at it and browse normally. 4 Switch the network Set the router to hand out the Pi-hole for DNS. 5 Tune Watch the log and add narrow exceptions. 6 Maintain Update software and lists, and back up settings. Prepare the host Update the system and give it a fixed address. 1 Install Follow the project's current instructions. 2 Test one device Point a single computer at it and browse normally. 3 Switch the network Set the router to hand out the Pi-hole for DNS. 4 Tune Watch the log and add narrow exceptions. 5 Maintain Update software and lists, and back up settings. 6

What about a backup DNS server?

It's tempting to list a public resolver as the secondary. Devices don't treat the second entry strictly as a backup: many use it whenever they like, so blocked names resolve some of the time.

For real redundancy, run a second Pi-hole on separate hardware and hand out both. Otherwise accept that one machine is a single point of failure, and write down how to revert the router setting. Anyone else in the house should know that step, since a dead Pi-hole looks like a dead internet connection.

Living with it

The dashboard shows the queries, which were blocked and which devices ask the most. When a site or app misbehaves, open the query log, reproduce the problem and look for blocked entries at that moment. Add an allow rule for the specific name. Disabling blocking for a few minutes is a quick way to confirm that Pi-hole is the cause.

Choose block lists with restraint. A moderate, well-maintained set causes far fewer breakages than a huge pile of overlapping ones. After changing lists, or periodically, refresh them.

pihole -g     # rebuild the block list database
pihole -up    # update Pi-hole itself

Command options can change between major versions, so run pihole -h to confirm. Export the settings from the web interface before big updates, and keep the host's operating system patched.

Groups, local names and other extras

Beyond blocking, a few features make it more useful. Groups let you apply different lists to different devices, so a child's tablet can be stricter than a work laptop. This depends on Pi-hole seeing individual devices, another reason to hand out its address through DHCP.

Local DNS records let you give names to things on your network, such as nas.home.arpa, which every device then resolves. That beats editing a hosts file on each computer.

Conditional forwarding sends reverse lookups for your local addresses to the router, which can help show device names instead of bare numbers in the dashboard when the router handles DHCP.

You can also add rules using pattern matching to block families of hostnames. Test patterns carefully, since a loose one can block far more than you intended, and the symptom may not show up until days later.

Troubleshooting common problems

Symptom Likely cause What to try
Nothing is being blocked Devices still use another resolver Check the device's DNS settings and renew its lease
All queries show as the router Only the router's upstream was changed Set the Pi-hole in the DHCP options instead
One app fails to sign in A needed domain is on a list Find it in the query log and allow it
No names resolve at all Host is down or upstream unreachable Check power, network and pihole status
Blocking works only sometimes A second, unfiltered DNS server is advertised Remove it, including any IPv6 entry

A wrong system clock on the host can also cause failures, especially if you use DNSSEC validation or encrypted upstreams. Boards without a battery-backed clock may start with the wrong time after a power cut until they can synchronize.

Looking after the machine

Small computers that run from memory cards can suffer card wear or corruption after sudden power loss. Use a good card or a solid-state drive, shut the system down cleanly and keep an exported copy of your settings on another device. With that file and a fresh installation, rebuilding takes minutes instead of an evening.

Check in every month or two. Apply operating system and Pi-hole updates, glance at the dashboard for devices behaving oddly and read the release notes before a major upgrade.

What it won't block

Content Blocked? Why
Ads from third-party ad domains Usually The name is on a list
Video ads served from the video's own domain Usually not Blocking the name would block the video
Sponsored posts inside a social feed No They arrive with the other content
Trackers on listed domains Usually The lookup fails
Devices using their own encrypted DNS No They never ask the Pi-hole
Anything on mobile data No The device is off your network

A content blocker in the browser can remove page elements and filter by full address, so many people use both. Some pages leave empty boxes where blocked ads would have been.

Privacy and security

Pi-hole keeps a history of lookups, which says a lot about everyone in the house. Lower the logging detail or retention if you don't need it, and tell household members what's recorded.

Protect the web interface with a strong password and keep it reachable only from your own network. Never forward port 53 from the internet to it. An open resolver can be abused in attacks on others. To use your blocking while away, connect to your home network through a VPN, as described in self-hosting a VPN.

Encrypted DNS settings in browsers or phones can quietly skip the Pi-hole. Check those on devices you manage. To encrypt the Pi-hole's own upstream queries, or to have it resolve names by working from the root servers with an additional local resolver, follow the project's guides. Recursive and authoritative servers explains what the second option changes.

Is it worth it?

It's a good fit if you want blocking on devices that can't run an ad blocker, you like seeing what your network is doing and someone in the house can fix it. If nobody wants to maintain a server, a hosted filtering resolver entered into the router gives much of the benefit with far less work.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in DNS & Domain Names →

Latest news on this topic