All guides

How to Block Ads on Every Device with a Raspberry Pi

Block ads and trackers for every device on your WiFi with DNS filtering on a Raspberry Pi 5 router. Setup steps, allowlist fixes and the honest limits.

Browser ad blockers only protect the browser they are installed in. Your smart TV, games console and the apps on your phone get nothing from them. Blocking at the network level covers all of those at once, and a Raspberry Pi 5 running Telepi OS does it with one switch.

How DNS blocking works

Before a device can load anything from the internet, it has to turn a name such as example.com into a numeric address. It asks a DNS server to do that, a bit like looking up a name in a phone book.

A web page or app typically triggers many of these lookups: one for the content, and more for advertising and tracking services hosted elsewhere. A filtering DNS server answers the ordinary lookups as usual and refuses the ones for known ad, tracker and malicious domains. With no address to go to, the device never connects, so the ad never downloads.

Nothing in the page itself is inspected or rewritten. The filter only decides which names resolve.

Why do it at the router

Every device on a network asks the router where to find DNS. If the router is the filter, then:

  • Every device is covered, including TVs, consoles and other devices that cannot run a blocker.
  • Nothing is installed on any of them.
  • There is one place to adjust the rules and to see what happened.
  • Guests are covered too from the moment they join your WiFi.

Telepi has a DNS server with filtering built in, so the Pi that provides your WiFi is also the ad blocker. There is no second box and no separate software to maintain.

What you need

A Raspberry Pi 5 running Telepi OS, with your devices connected to its WiFi. If you have not built one yet, start with How to build a router with a Raspberry Pi 5.

At home you do not have to replace your ISP's router. Put Telepi behind it, connected by WiFi or by an Ethernet cable, and move your devices to the Telepi WiFi. Only devices connected to Telepi are filtered.

Set it up

  1. Join the Telepi WiFi and open http://192.168.111.200:8080. Sign in (admin / telepi.com unless you have changed it, which you should).
  2. Open the DNS Server page.
  3. Make sure Block Ads & Trackers is switched on. Its description reads "Blocking ads, trackers, and malicious domains".
  4. Switch on Force DNS Redirection. Some devices are set to use a fixed DNS server such as 8.8.8.8 and would otherwise skip your filter. With this on, all DNS queries from clients are redirected to the router anyway.

Telepi DNS Server page with the Block Ads & Trackers and Force DNS Redirection switches

The same page shows statistics: total queries, blocked, allowed, and the cache hit rate. Browse for a few minutes and the blocked count should start to rise.

Add your own rules

The built-in blocking handles the common cases. Two tabs let you adjust it:

  • Blocklist — your own list of domains to block, one per line. Use it for anything the built-in filter does not cover.
  • Allowlist — domains that must always resolve, whatever the filter says.

See what is being blocked

The Logs tab lists recent DNS queries and whether each one was allowed or blocked. It is the quickest way to learn what your devices are doing on the network, and it is where you go when something stops working.

Telepi DNS Logs tab showing recent queries marked allowed or blocked

Un-break a site with the allowlist

Occasionally a site or app depends on a domain that the filter blocks. A login button does nothing, a video will not start, or a shopping link goes nowhere. To fix it:

  1. Open the Logs tab on the DNS Server page.
  2. Reproduce the problem on the affected device: reload the page or reopen the app.
  3. Look in the log for blocked entries that appeared at that moment.
  4. Add the domain that looks related to the Allowlist tab.
  5. Try again. A device may remember the old answer for a short while, so reload or restart the app if nothing changes at first.

If you cannot tell which domain is responsible, switch Block Ads & Trackers off briefly to confirm that the filter is the cause, then switch it back on and work through the blocked entries one at a time. Add only what you need; each allowlisted domain is one the filter no longer touches.

What this won't do

DNS blocking is effective, but it has clear limits.

  • Ads from the same domain as the content. The filter blocks by domain name. When ads come from the same domain as the thing you are watching, as with YouTube in-stream ads, there is nothing separate to block. Expect those to remain.
  • DNS-over-HTTPS in a browser. A browser set to use DNS-over-HTTPS sends its lookups encrypted to its own provider. Force DNS Redirection does not stop that. Turn the feature off in the browser's settings if you want that browser filtered.
  • VPN apps on a device. A device running its own VPN app sends its traffic, lookups included, through the VPN and around the filter.
  • Devices not on Telepi. A phone on mobile data, or on someone else's WiFi, is not filtered.
  • Empty spaces. Because pages are not rewritten, a blocked ad can leave a blank box where it would have been.

Next steps