An Engineer's Blog

Back

Cloudflare DDNS and split-brain DNS with OPNsense and AdGuard HomeBlur image

Overview

Every service in this homelab has one public name that has to work identically from the couch and from a hotel Wi-Fi. The split-brain part answers the same name with a different IP depending on which side of the firewall the query comes from.

DNS flow: clients, AdGuard Home, Unbound, DoT upstream, DDNS, split-brain answers

The host and guest layout live in the homelab write-up. Every hop here has a simpler or more modern alternative; this shape survived my ISP changes and my own tinkering.

The resolver chain

Three resolvers, one job each:

LAN clients
  -> AdGuard Home       :53     filtering, caching, the only resolver clients see
  -> Unbound (OPNsense) :53     DNSSEC, recursion, DoT upstream
  -> dnsmasq (OPNsense) :53053  authoritative for home.arpa, DHCP leases
text

AdGuard Home runs in an LXC on the core range with its sole upstream on the OPNsense LAN IP; the firewall allows no direct DNS path out, so pointing a client at a public resolver cannot bypass filtering. The Proxmox host resolves through AdGuard too (search home.arpa, nameserver pointing at AdGuard). Is one strict chain over-engineered for a household? Probably. But DNS is the first thing to break when everything else looks fine, and walking one known chain beats debugging whatever the router ships with.

AdGuard Home: filter and cache

Four filter lists, query log kept local. The cache settings made repeated lookups noticeably faster:

SettingValueEffect
cache_size10 MBplenty for a household
cache_ttl_min60 sshort-lived records stop hammering upstream
cache_ttl_max86400 slong records stay cached for a day
cache_optimistictrueexpired entries are served stale, then refreshed in the background
aaaa_disabledtruethe LAN is IPv4-only, so AAAA queries get instant empty answers

cache_optimistic matters most when the upstream is slow or down: clients keep getting last-known answers instead of timeouts. None of these numbers are gospel; I tuned them against the query log until repeat lookups felt instant, and a bigger household would outgrow them.

Bootstrap resolution runs over encrypted DNS (9.9.9.10), so the resolver does not bootstrap itself in plaintext. One rewrite maps agh.home.arpa to the AdGuard container itself, giving the admin UI a stable local name.

DDNS with Cloudflare

The ISP cycles the WAN IP, and a few services need a direct path around the Cloudflare Tunnel for raw throughput. The updater is the DynDNS plugin on OPNsense itself, ddclient backend in Cloudflare token mode.

service:   Cloudflare API, zone-scoped token
zone:      the public domain
hostnames: 10 A records, including the firewall's own pve-ddns name
checkip:   web (icanhazip), 10 s timeout
ttl:       300
text

No extra container, and the check source (icanhazip) sees the WAN IP from the box that owns the WAN interface. TTL stays at 300 s so an ISP change propagates fast. A dedicated updater container would do the same job; I preferred one less thing to restart, and the plugin has been correct across every address change so far. A cron job also renews the WireGuard resolvers nightly to clear stale DNS state on the tunnels.

Split-brain: one name, two answers

This is what makes bookmarks portable:

inside:   jellyfin.<domain>  ->  Caddy, TLS terminates locally
outside:  jellyfin.<domain>  ->  Cloudflare edge -> tunnel or DDNS A record
text

Internally, Unbound host overrides do the work: one host record points caddy.home.arpa at the reverse proxy, and 40 aliases bind the public subdomains (pve, jellyfin, files, hass, scrypted, and the rest) onto it. A LAN client asking for a public name reaches the proxy without hairpinning through the ISP path, and Caddy serves the certificate for the exact name requested.

Externally the same names live as Cloudflare records: most ride the cloudflared tunnel (no open ports at all), the ten DDNS hostnames are plain A records on the WAN IP. authelia.<domain> is a CNAME into Cloudflare Access, so the same SSO flow protects the tunneled and direct paths alike.

The internal-only zone stays fully authoritative on dnsmasq at port 53053, a hundred-plus static host entries, one per service and device, each with a description. Unbound forwards home.arpa queries to it over DoT on loopback, and the private-domain option stops rebinding protection from eating the answers.

Other DNS tricks on the box

  • Per-client DNS via DHCP tags. The dnsmasq DHCP server groups options into tags: the default range hands out AdGuard, while hosts routed through a VPN tunnel get that tunnel provider’s own resolver. A policy-routed host resolving through the wrong resolver is a leak; the tag closes it at assignment time.
  • The firewall knows its own IP. A WAN_IP alias is a URL table pointing at https://127.0.0.1/dynamic_ip.txt, a tiny endpoint the firewall serves itself with the current WAN address, refreshed every six minutes. Rules reference “my own WAN IP” symbolically instead of a literal address that changes.
  • Recursive hardening on Unbound. Aggressive NSEC, prefetch, serve-expired with TTL reset, hide-identity/hide-version, and 50 MB/100 MB message and RRSet caches with a 24 h max TTL. Each one measurably cuts upstream load.
  • Everything resolves through AdGuard: host, containers, VMs, the search home.arpa domain. One query log shows every name the household looked up, which is half of debugging.

Total moving parts a reboot can break: two resolvers and one updater, on machines that boot in under a minute and start in the right order. Would I build it this way again? Mostly, yes.

Cloudflare DDNS and split-brain DNS with OPNsense and AdGuard Home
https://tin.ng/blog/2026-09-06--cloudflare-ddns-split-brain-dns-opnsense-adguard
Author Tin Nguyen
Published at September 6, 2026
Comment seems to stuck. Try to refresh?✨