Originally published at blog.gustl.icu/en/posts/dns-blocker.
Anyone who wants to set up a DNS blocker gets the same advice: Pi-hole on a small machine, enter it as DNS in the router, done. That works. It also works without the package — with the resolver that is running anyway, a list and one cron entry. And there is a second part that no guide covers: some sites only answer if the request comes from a particular country. That needs an exit of your own for exactly those sites.
I describe both on the setup we run, with today's numbers. A gateway in the mesh answers name resolution for the machines that ask it.
What "server-side" means
A DNS blocker is not a filter in the browser. It answers the question "what is the address of this name?" with an address where nothing is reachable. The device believes the server is down and gives up.
The advantage is that it applies to everything using this resolver: the television, the phone, the game console, the machine without an ad-blocking extension. Nothing is installed on any of them. The disadvantage sits in the same place: whoever enters a different resolver bypasses the block — and modern browsers do that by themselves, more on that below.
The setup
The gateway runs dnsmasq, bound to its one address in the mesh. It does not listen on the public address nor in the home network; to ask it you have to be in the mesh.
The mesh is our private network over WireGuard: every machine builds a tunnel to a node, gets an address from a range of its own, and the resolver is reachable only under that address. From outside nobody sees it, and a device without a tunnel gets no answer. How that is built is described in Two tunnels, one network.
The blocklist is a file in its configuration directory:
| Item | Value (measured 1 Dec 2026) |
|---|---|
| File | /etc/dnsmasq.d/adblock.conf |
| Size | 80,732 blocked names, 3.0 MB |
| Form | one line address=/name/0.0.0.0 per domain |
| Sources | StevenBlack, AdAway, Peter Lowe, Dan Pollock |
| Generation | daily at 03:00 by cron, then systemctl restart dnsmasq
|
| Check | a query for doubleclick.net answers 0.0.0.0
|
Alongside it, a short list of exceptions:
server=/stream.example/9.9.9.9
server=/forum.example/9.9.9.9
server=/domain/resolver means: for this domain do not ask the defaults but this server. The domain therefore passes the blocklist — intended, if you need it.
A line of the list looks like this, and dnsmasq needs nothing more:
address=/doubleclick.net/0.0.0.0
Upstream it asks three public resolvers; the cache holds 1000 answers. That is the whole setup.
What it blocks and what it does not
A test with three queries shows both the effect and the limit:
doubleclick.net → 0.0.0.0 (from the list)
example.com → real address (not in the list)
xyz123unwahrscheinlich.example → NXDOMAIN
So the block is an answer with an address that leads nowhere. That is enough for ad networks that appear under their own name. It can be checked with a query:
dig +short doubleclick.net @<address-of-the-resolver>
dig +short example.com @<address-of-the-resolver>
Three cases remain — and they are the reason figures in reports look better than actual browsing:
Ads from the same domain. If a site serves its ads under its own name, blocking the name blocks the site. That happens constantly with large platforms.
Ads by address rather than by name. An ad network addressed directly by IP never asks for a name. DNS never sees it.
Encrypted name resolution in the browser. Firefox and Chrome can speak DNS over HTTPS: the query leaves as an encrypted web request to a public resolver, past ours. Mozilla has provided a signal against that — the "canary domain". Firefox resolves use-application-dns.net through the configured resolver; a negative answer — NXDOMAIN or an answer without an address — is the signal to turn DoH off.
The signal only applies to browsers where DoH is the default. Whoever enables DoH in the settings themselves never asks, and Mozilla itself describes the mechanism as temporary. How a given Firefox build behaves therefore depends on the version and on the setting.
In our setup the resolver answers that name with a real address. As long as it does, Firefox does not see the signal and keeps DoH. The reason is the form of the answer: the blocklist answers NOERROR with 0.0.0.0 instead of NXDOMAIN — a blocked name looks like an existing one. Whoever wants to use the signal has to deny the canary domain explicitly. Against DoH itself there is little help in the network: it runs over port 443 and looks like an ordinary web request. You can block the known DoH addresses and block DoT on port 853 — not more.
That is the point where a DNS blocker stops being a block and starts being a brake.
Your own exit for particular sites
The second part has nothing to do with ads. Some services answer only if the request comes from a particular country: media libraries, gambling, banks, forums. Accessing from abroad gets you an error page or nothing at all.
A VPN solves that — but not the way people think. WireGuard routes by address, not by name. You cannot say "this site through the tunnel, the rest direct"; you can only say "this address through the tunnel". The name first has to become an address.
Our route therefore has two stages and runs every hour:
- A list names the domains that should go through the other exit.
- A script asks the public resolver for those names and collects the addresses in a set (
ipset). - For every address in that set a route appears via the peer that forms the exit.
- The DNS exceptions from the previous section make sure the names resolve at all and do not get stuck in the blocklist.
In commands the whole procedure is this:
ipset add whitelist <address> -exist
ip route add <address> via <peer> dev wg0
ip route del <address> # when the address no longer applies
Measured today: 23 addresses in the set, 23 routes, one run every 59 minutes by cron. The script also cleans up: addresses no longer in the set lose their route. Otherwise a good part of the world accumulates over time.
What that means in operation:
- The exit applies to the address, not the name. If the site picks up a different address, the rule only applies on the next run. With some services that changes by the minute.
- Shared addresses. Large websites sit behind the same distributor as a hundred others. Redirecting the address sometimes redirects more than intended.
- It applies to everyone in the network. A route is not a browser setting. Whoever uses the other exit does so for every device touching that address.
- The exit is only as good as the peer. If it fails, exactly those sites fail; the rest keeps running.
What the setup does not solve
Both parts have the same weak spot, just at different ends. The block applies to devices that ask — a browser with a resolver of its own does not ask. The exit applies to addresses on the list — a site that moves elsewhere tomorrow goes out directly again.
Neither is a fault in the setup but a property of the network: names are resolved in many places, and addresses change. Whoever wants more needs a firewall that sees the traffic itself and not just the question about it. In my experience that costs more maintenance than it gives back in quiet.
Whoever wants to rebuild this needs a machine that always runs, dnsmasq, a blocklist in its format, a cron entry that restarts the service afterwards — and, in the router, the entry that sends the devices there. A Pi-hole is more convenient because it fetches the list itself and brings a dashboard. It is not necessary.
Sources
All addresses retrieved on 1 December 2026, each answered HTTP 200.
- Pi-hole, overview (DNS sinkhole, blocking without software on the devices): https://docs.pi-hole.net/
- AdGuard Home, overview (alternative with filter lists and a dashboard): https://adguard.com/en/adguard-home/overview.html
- RFC 8484, DNS over HTTPS: https://www.rfc-editor.org/rfc/rfc8484
- RFC 7858, DNS over TLS: https://www.rfc-editor.org/rfc/rfc7858
- Mozilla, canary domain
use-application-dns.net(when Firefox turns DoH off): https://support.mozilla.org/en-US/kb/canary-domain-use-application-dnsnet -
dnsmasq, manual page (optionsserver=,address=,addn-hosts): https://manpages.ubuntu.com/manpages/resolute/man8/dnsmasq.8.html -
ip-route, manual page (routes via a device, tables): https://manpages.ubuntu.com/manpages/resolute/man8/ip-route.8.html - WireGuard, quick start (
AllowedIPsworks with addresses, not names): https://www.wireguard.com/quickstart/ - Wikipedia, DNS sinkhole (term and mode of operation): https://en.wikipedia.org/wiki/DNS_sinkhole
Top comments (0)