DNS that devices can't bypass
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:
- Hard-coded DNS. Smart TVs, streaming sticks and some apps ignore the DNS server DHCP hands them and talk straight to 8.8.8.8 or 1.1.1.1.
- DNS-over-TLS and DNS-over-QUIC. Android's "Private DNS" setting and some apps encrypt DNS on port 853, so the filter never sees it.
- DNS-over-HTTPS. Browsers and apps can send DNS inside normal HTTPS traffic on port 443, which looks like any other web request.
- VPN apps. A VPN tunnels everything, DNS included, around every control on the network.
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
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.
| Network | DNS redirect | DoT/DoQ block | DoH blocks | VPN block |
|---|---|---|---|---|
| LAN (trusted) | Yes, with the hairpin fix | Yes | Yes | No: Tailscale and my own VPN use |
| IoT | Yes | Yes | Yes | Yes |
| Media (TVs, speakers, kids' phones) | Yes | Yes | Yes | Yes |
| Guest (visitors, work laptop) | Yes | Yes | Yes | No: the work VPN must connect |
| Server | Yes | Yes | Yes | No: servers need their tunnels |
| DMZ | Not needed: egress is Cloudflare only | Not needed | Not needed | Not 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 attempt | How I tested it | Expected | Result |
|---|---|---|---|
| Plain DNS to a public resolver | dig @8.8.8.8 <blocked domain> | Answered by Pi-hole, blocked | Blocked (redirected) |
| Plain DNS on the LAN, after the redirect | Same test from a LAN client | Answer arrives, blocked | Timed out at first; worked after the hairpin rule |
| DNS-over-TLS | kdig +tls @1.1.1.1 <domain> | No connection | Timed out |
| DNS-over-QUIC | A DoQ query to a public resolver on UDP 853 | No connection | Worked until the rule covered UDP; then timed out |
| DNS-over-HTTPS by name | Browser set to a DoH provider | Lookup of the DoH server fails, browser falls back | Fell back to system DNS |
| DNS-over-HTTPS by IP | curl https://1.1.1.1/dns-query | No connection | Timed out |
| Phone with DNS set manually to 8.8.8.8 (Guest network) | Open a blocked site | Still blocked | Blocked |
| Android Private DNS set to a public provider | Open a blocked site | Falls back to normal DNS, blocked | Blocked |
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.
- Unlisted DoH servers. Layers 3 and 4 only stop DoH servers that are on the lists. A private or brand-new DoH endpoint on port 443 would get through until the lists catch up.
- Privacy relays. Apple's iCloud Private Relay runs over normal HTTPS ports, so the VPN-port block doesn't touch it. Pi-hole can block its domains, and iPhones then fall back to normal DNS. That's next on my list for the kids' phones.
- Allowed VPNs. On the networks where VPNs are permitted (LAN, Guest, Server), a VPN still goes around everything. That's a deliberate trade-off: the work laptop's VPN has to work.
- Side effects. Blocking DoH by IP also blocks HTTPS to those addresses, so typing
https://1.1.1.1into a browser now fails. That briefly confused my own testing of a new network, until I remembered why.
What I took from it:
- Layers, not a single rule. Each bypass needed its own control; any one alone leaves an obvious gap.
- Check both protocols. Two of the bugs were a TCP-only rule where UDP mattered too, and vice versa. Every DNS rule is TCP and UDP now.
- Redirects have return paths. NAT tricks that work across networks can fail inside one; the hairpin rule fixed what the redirect broke.
- Fail toward the filter. The blocks don't just stop bypasses, they push devices back onto the filtered path, so nothing visibly breaks for the people using them.
Next: block Private Relay's domains, add a threat-intelligence blocklist to Pi-hole, and give the kids' phones a stricter Pi-hole group.