← All notes

DNS that devices can't bypass

Joseph Henry Cariazo ·

Every device in my house now uses my DNS filter whether it wants to or not: hard-coded DNS servers are quietly redirected, and encrypted DNS that would slip past the filter is blocked. This is how the four layers work, what broke while building them, and how I tested each one.

Why

Pi-hole only protects the devices that ask it. Many don't:

On a network with smart devices and kids' phones, each of these is a real way around the filter. The goal: plain DNS always ends up at Pi-hole, encrypted DNS to outside resolvers simply doesn't connect, and devices fall back to the filtered path.

Where each bypass is stopped

Every DNS bypass ends at Pi-hole or a block Every DNS bypass ends at Pi-hole or a block Bypass attempt Control Outcome Plain DNS (port 53) Destination NAT redirect Answered by Pi-hole DoT / DoQ (port 853) Floating block, TCP/UDP 853 Falls back to Pi-hole DoH by name Pi-hole DoH blocklist Falls back to Pi-hole DoH by IP (port 443) Floating block, DoH IP alias Falls back to Pi-hole VPN apps VPN port block (IoT, Media) Blocked
Plain DNS is answered by Pi-hole whatever server the device asked for; encrypted DNS to outside resolvers can't connect, so devices fall back to the system DNS, which is Pi-hole.

Building it

The DNS chain itself: clients ask Pi-hole, which filters ads, trackers and known-bad domains, then forwards to Unbound on the OPNsense firewall, which resolves upstream over DNS-over-TLS. The four layers below make sure nothing goes around that chain.

Layer 1: redirect plain DNS to Pi-hole

A destination NAT rule on every internal network catches port 53 traffic aimed at anything other than the firewall and rewrites it to Pi-hole. Pi-hole itself is excluded so its own upstream queries don't loop back. A TV that insists on 8.8.8.8 gets Pi-hole's filtered answer and never notices.

What broke: on the LAN, where Pi-hole sits in the same subnet as the clients, redirected queries timed out. The client sent its query to 8.8.8.8, but Pi-hole replied directly from its own address, so the client threw away an answer from a server it never asked. A source NAT (hairpin) rule on the LAN makes the reply come back through the firewall, from the address the client expects. Other VLANs don't need it, because their traffic already crosses the firewall both ways.

Layer 2: block DNS-over-TLS and DNS-over-QUIC

A floating firewall rule blocks port 853 on the internal networks. It covers Android's Private DNS, which then falls back to normal DNS and lands in layer 1.

What broke: the first version only blocked TCP. DNS-over-TLS uses TCP, but DNS-over-QUIC uses UDP on the same port, so it kept working until the rule was changed to TCP and UDP. The same lesson applied to every DNS rule on every network: plain DNS also needs both, because it falls back to TCP for larger answers.

Layer 3: block DNS-over-HTTPS by name

Pi-hole subscribes to HaGeZi's DoH blocklist. When a browser or app looks up a known DoH server (dns.google, cloudflare-dns.com and hundreds more), Pi-hole returns nothing, and the client falls back to the system DNS.

Layer 4: block DNS-over-HTTPS by IP

Some clients skip the lookup and connect to a DoH server by IP address, which layer 3 never sees. A URL Table alias in OPNsense pulls HaGeZi's list of DoH server IPs and refreshes it on a schedule, and a floating rule blocks port 443 to those addresses on the internal networks. The DMZ is left out: its rules already allow nothing but Cloudflare.

Per-network choices, including VPNs

VPN apps would tunnel around all four layers, so the IoT and Media networks also block the common VPN ports (WireGuard, OpenVPN, IPsec, L2TP, PPTP, Tailscale). Smart devices have no reason to build tunnels, and on Media it stops VPN apps on the kids' phones.

NetworkDNS redirectDoT/DoQ blockDoH blocksVPN block
LAN (trusted)Yes, with the hairpin fixYesYesNo: Tailscale and my own VPN use
IoTYesYesYesYes
Media (TVs, speakers, kids' phones)YesYesYesYes
Guest (visitors, work laptop)YesYesYesNo: the work VPN must connect
ServerYesYesYesNo: servers need their tunnels
DMZNot needed: egress is Cloudflare onlyNot neededNot neededNot needed

Proving it

Each layer was tested from a client on the network by trying exactly what a bypassing device would do, using a domain that Pi-hole blocks.

Bypass attemptHow I tested itExpectedResult
Plain DNS to a public resolverdig @8.8.8.8 <blocked domain>Answered by Pi-hole, blockedBlocked (redirected)
Plain DNS on the LAN, after the redirectSame test from a LAN clientAnswer arrives, blockedTimed out at first; worked after the hairpin rule
DNS-over-TLSkdig +tls @1.1.1.1 <domain>No connectionTimed out
DNS-over-QUICA DoQ query to a public resolver on UDP 853No connectionWorked until the rule covered UDP; then timed out
DNS-over-HTTPS by nameBrowser set to a DoH providerLookup of the DoH server fails, browser falls backFell back to system DNS
DNS-over-HTTPS by IPcurl https://1.1.1.1/dns-queryNo connectionTimed out
Phone with DNS set manually to 8.8.8.8 (Guest network)Open a blocked siteStill blockedBlocked
Android Private DNS set to a public providerOpen a blocked siteFalls back to normal DNS, blockedBlocked

The firewall's live log during the tests showed the 853 and DoH-IP attempts as blocks, and the redirected port 53 traffic arriving at Pi-hole's query log under the client's own name.

Limits and lessons

No DNS control is complete, and it's worth being clear about what this one doesn't cover.

What I took from it:

Next: block Private Relay's domains, add a threat-intelligence blocklist to Pi-hole, and give the kids' phones a stricter Pi-hole group.

← All notes