internal DNS: lab.internal resolver on the WG hub (dnsmasq on rpi)

WireGuard clients apply the tunnel DNS to the whole device, so the hub
resolver answers lab.internal authoritatively and forwards everything else:

- dnsmasq on rpi, bound to lo/wg0/wg-remote only, 10.10.0.1 + 10.20.0.2
- grafana.lab.internal, hubble.lab.internal -> 10.10.0.2 (hosts file, one
  line per record)
- ufw: 53 allowed from 10.10.0.0/24, 10.20.0.0/24, 10.244.0.0/16; dropped
  everywhere else, inserted above the LAN catch-all
- docs: zone, per-client instructions (phone is a linode-hub spoke), rollback
This commit is contained in:
Lance Walters 2026-10-27 01:03:42 -04:00
commit ead60fface
6 changed files with 365 additions and 0 deletions

View file

@ -436,3 +436,211 @@ node that does not run the backend completes the TCP handshake and never ACKs
(the same co-location fault as the public gateway). The Gateway status lists
both node addresses because the class schedules on every `gateway=true` node;
the working address is the one the backends are pinned to, `10.10.0.2`.
## 11. Internal DNS: the `lab.internal` zone
Facts: zone `lab.internal`, resolver `10.10.0.1` (and `10.20.0.2`), records
`grafana.lab.internal` and `hubble.lab.internal` → `10.10.0.2`, configured by
`infrastructure/networking/internal/dns/`. The record does **not** carry a
port: Grafana stays on `:8081`, Hubble UI on `:8084`, so the URLs are
`http://grafana.lab.internal:8081/` and `http://hubble.lab.internal:8084/`.
### 11.1 What "split DNS" can and cannot mean here
The WireGuard clients in use (Android, iOS, and the desktop clients) hand the
tunnel's DNS server to the OS as **the device resolver for everything while
the tunnel is up**. There is no client-side per-domain split, and nothing on
the server side can create one. So:
- the resolver on the hub **answers `lab.internal` itself** (authoritative,
`local=/lab.internal/`, never forwarded), and
- **forwards every other query** to the upstreams in the Pi's
`/etc/resolv.conf` (today `100.100.100.100` = Tailscale MagicDNS, which
forwards to the ISP resolvers `137.118.204.9` / `137.118.1.32`).
Public resolution therefore keeps working *through* the tunnel resolver — it
is not "split on the client", it is "one resolver that knows one private zone
and forwards the rest". Public names stay on public DNS; there are no
split-horizon records for `siriusdevops.com`, `piedmonthomesvc.com` or
`siriusgrowthsolutions.com` and there must not be.
**The risk this creates:** while the tunnel is up, a dead resolver is a dead
internet connection for that device. Rollback is in §11.6.
### 11.2 Where it runs, and why not in the cluster
`dnsmasq` **on rpi** — the WireGuard hub, `10.10.0.1` on `wg0` and `10.20.0.2`
on `wg-remote`. It is a host service, deliberately **not** behind Cilium's
internal Gateway: those listeners have their own failure mode (`t_e9564aa3`,
Envoy on the wrong node answers 503 after 5 s) and DNS must not inherit it.
Host ports on the Pi over WireGuard work (SSH on `10.10.0.1:22` is proof).
dnsmasq was already the Pi's resolver (it also answers `.rpi.local`), so this
extends it instead of adding a second resolver on port 53. Artifacts:
| File | Installed to | Purpose |
|---|---|---|
| `dns/lab-internal.conf` | `/etc/dnsmasq.d/lab-internal.conf` | zone authority, `addn-hosts`, bind list |
| `dns/lab-internal.hosts` | `/etc/dnsmasq-lab-internal.hosts` | the records (hosts(5) syntax) |
| `dns/rpi-ufw-dns.sh` | — | ufw allow/deny for `:53` |
| `dns/install-rpi-dns.sh` | — | installs all of the above, restarts, prints bind view |
The hosts file lives **outside** `/etc/dnsmasq.d` on purpose: the unit passes
`-7 /etc/dnsmasq.d`, so every file in that directory is parsed as config, and a
hosts file there fails the start with `bad option at line 9`.
Install / re-install (host artifacts — a Pi reinstall has to re-run this):
```bash
bash infrastructure/networking/internal/dns/install-rpi-dns.sh # as root on rpi
```
### 11.3 Listen addresses and the firewall boundary
`bind-dynamic` + `interface=lo`, `interface=wg0`, `interface=wg-remote`:
53 is bound on `127.0.0.1`, `10.10.0.1`, `10.20.0.2` (and `::1`) and **nowhere
else** — not on `192.168.1.125`, not on the tailscale address. `bind-dynamic`
also means a WireGuard interface that is down at boot is picked up when it
appears, with no restart and no hard `Requires=` on a `wg-quick@` template unit.
ufw is the second layer (and the one that produces the DROP evidence), inserted
above the `allow from 192.168.1.0/24` catch-all:
```
53/udp,tcp ALLOW IN 10.10.0.0/24 # mesh (siriussec, Pi-hub peers)
53/udp,tcp ALLOW IN 10.20.0.0/24 # remote hub + its spokes (the phone, Legion)
53/udp,tcp ALLOW IN 10.244.0.0/16 # pods
53/udp,tcp DENY IN Anywhere # LAN, tailscale, internet
```
`10.20.0.0/24` is not optional: the phone and Legion are spokes of the
**linode** hub (`10.20.0.1`), so their DNS packets reach the Pi on `wg-remote`
with source `10.20.0.3` / `10.20.0.5`. With only the mesh subnet allowed, the
hub-spoke clients time out (§11.7 negative 3).
No Cloudflare change: the tunnel's ingress list is an allow-list of HTTP
hostnames pointing at `:8080`; UDP/TCP 53 is not proxied by it and there is no
port-forward on the LAN edge. `*.lab.internal` has no public record.
### 11.4 Adding a record
1. Add one line to `dns/lab-internal.hosts` — `<address>\t<name>` — commit it.
2. On rpi: `sudo install -m 0644 dns/lab-internal.hosts /etc/dnsmasq-lab-internal.hosts
&& sudo systemctl reload dnsmasq` (a reload re-reads `addn-hosts`; no restart,
no dropped queries).
3. Verify: `dig +short <name> @10.10.0.1`.
Only `lab.internal` is authoritative. A query for anything else, *including*
`siriusdevops.com`, is forwarded — do not add public names here.
Which address to record: **`10.10.0.2`** today, because siriussec is the only
node carrying `node-role.kubernetes.io/gateway=true` and therefore the only one
with a listener that can complete a request to the backends. If that changes
(the label moving back to rpi once the arm64/Envoy co-location issue is solved),
it is a one-line change in `dns/lab-internal.hosts` + reload.
### 11.5 Client configuration
The phone is **`Pixel 9 Pro`**, WireGuard peer `10.20.0.3` on the **linode**
hub (`10.20.0.1:51820`) — not a `wg0` peer of the Pi: its handshake is
seconds old on the linode hub, while the Pi's `wg0` peer `10.10.0.4`
(`Peer SiriusMobile`) has been stale for days. Its DNS therefore has to be set
in the phone's own WireGuard profile. The Pi's `wg0.conf` peers (and the
`wgportal` DB) are *not* where the phone's DNS lives, and wgportal is not even
running on the Pi today (`docker ps` has no wgportal container) — so nothing on
the server side can push this; do not go looking for a portal toggle.
**Android (WireGuard app) — 3 steps:**
1. Open the WireGuard app → tap the tunnel → pencil (Edit) → **Interface**
section → **DNS servers** → enter `10.10.0.1` (leave "Excluded applications"
alone).
2. Save, then toggle the tunnel **off and on** (Android keeps the old
`resolver1` until the tunnel restarts).
3. Check: browser to `http://grafana.lab.internal:8081/` → login page; and any
public site still loads (proof forwarding works).
If that profile's `AllowedIPs` does not cover `10.10.0.0/24`, use **`10.20.0.2`**
(the Pi's address on the hub subnet) instead — both answer, both are the same
resolver.
**iOS:** WireGuard app → tunnel → Edit → *DNS Servers* → `10.10.0.1` → Save →
toggle off/on.
**Desktop (wg-quick):** in the tunnel's `[Interface]` add `DNS = 10.10.0.1`
and, because this is a non-systemd-resolved-specific option,
`resolvconf`/`openresolv` must be present (`wg-quick` uses it to point the
system resolver at the tunnel); then `wg-quick down <if> && wg-quick up <if>`.
There is no per-domain split — the whole machine uses it while the tunnel is
up.
Do not point a **cluster node** at this resolver: nodes and pods must keep
their own DNS (`CoreDNS` / `/etc/resolv.conf`) or kubelet and pod lookups will
break. This is for client devices only.
### 11.6 Rollback (do this first when DNS "breaks the internet")
On the device: WireGuard app → tunnel → Edit → clear the **DNS servers** field
→ Save → toggle the tunnel off/on. That restores the OS resolver immediately.
On the server: `sudo systemctl disable --now dnsmasq` stops the Pi's resolver
(don't — it also serves `.rpi.local`); to remove only the zone, delete
`/etc/dnsmasq.d/lab-internal.conf` and `/etc/dnsmasq-lab-internal.hosts` and
`systemctl restart dnsmasq`. To close the port again, remove the six `wg-dns`
ufw rules (`ufw status numbered`, then `ufw delete <n>`).
### 11.7 Verification log — 2026-10-27
Resolver: `dnsmasq` 2.91 on rpi, enabled at boot (`systemctl is-enabled dnsmasq`
= `enabled`), ufw `enabled`. Listeners (no `0.0.0.0`, no LAN address):
```
$ sudo ss -lntuH 'sport = :53'
udp 127.0.0.1:53 udp 10.10.0.1:53 udp 10.20.0.2:53 udp [::1]:53
tcp 127.0.0.1:53 tcp 10.10.0.1:53 tcp 10.20.0.2:53 tcp [::1]:53
$ sudo journalctl -u dnsmasq -n 4
using nameserver 100.100.100.100#53 # forwarded upstreams (tailscale MagicDNS)
using only locally-known addresses for lab.internal
read /etc/dnsmasq-lab-internal.hosts - 2 names
```
`10.10.0.1:8081`/`:8084` flap. `:53` does not: it is a host socket, not Envoy.
**Positive — from a WireGuard client (Legion, `10.20.0.5`, via the linode hub):**
```
$ dig +short grafana.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short hubble.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short grafana.lab.internal @10.20.0.2 -> 10.10.0.2
$ dig +tcp +short grafana.lab.internal @10.10.0.1 -> 10.10.0.2
$ dig +short example.com @10.10.0.1 -> 104.20.23.154 / 172.66.147.243 # forwarding
$ dig nosuch.lab.internal @10.10.0.1 -> status: NXDOMAIN # authoritative, not forwarded
```
From a mesh peer (`siriussec`, `10.10.0.2`): all three names `rcode 0`
(`grafana.lab.internal`, `hubble.lab.internal`, `example.com`). From the Pi's
own loopback: same, plus `nope.lab.internal` → `NXDOMAIN`.
**Negative — LAN and counters** (from Legion on `192.168.1.126`, same host that
resolved fine over the tunnel a second earlier):
```
$ dig +time=3 grafana.lab.internal @192.168.1.125 -> timed out, no servers could be reached
$ dig +tcp +time=3 grafana.lab.internal @192.168.1.125 -> timed out
$ sudo iptables -L ufw-user-input -n -v | grep dpt:53
2 120 ACCEPT tcp 10.20.0.0/24 dpt:53 # hub spokes (the phone's path)
3 188 ACCEPT udp 10.10.0.0/24 dpt:53 # mesh
7 602 ACCEPT udp 10.20.0.0/24 dpt:53
3 180 DROP tcp 0.0.0.0/0 dpt:53 # LAN / internet
1 89 DROP udp 0.0.0.0/0 dpt:53
```
**Regression:** `http://10.10.0.2:8081/` → 302 (Grafana login), `:8084/` → 200
(Hubble UI), public sites through the tunnel unchanged (no Cloudflare object
touched).
**Reboot survival:** `systemctl is-enabled dnsmasq` = `enabled`; the unit
`Requires=network-online.target` and has **no** `Requires=`/`After=` on any
`wg-quick@` template (which is `enabled` but currently `inactive` because `wg0`
was brought up by hand — a hard dependency would fail the boot). `bind-dynamic`
picks up `wg0`/`wg-remote` whenever they appear. Records and the bind list live
in `/etc/dnsmasq*`, not in `/run`; ufw rules are persistent.

View file

@ -0,0 +1,56 @@
# `lab.internal` resolver (WireGuard only)
Authoritative for the `lab.internal` zone and a forwarder for everything else,
running as **dnsmasq on rpi** (the WireGuard hub) at `10.10.0.1:53` and
`10.20.0.2:53`. It is a **host** service, not a cluster object — deliberately
not behind Cilium's internal Gateway, so it cannot inherit the Envoy
listener flapping (`t_e9564aa3`).
Full write-up, client instructions and rollback: `docs/internal-wireguard-services.md` §11.
## Files
| File | Installed to | Purpose |
|---|---|---|
| `lab-internal.conf` | `/etc/dnsmasq.d/lab-internal.conf` | zone authority (`local=/lab.internal/`), records file, bind list |
| `lab-internal.hosts` | `/etc/dnsmasq-lab-internal.hosts` | records, hosts(5) syntax — one line per name |
| `rpi-ufw-dns.sh` | — | ufw: allow 53 from mesh/hub-spokes/pods, deny everything else (inserted above the LAN catch-all) |
| `install-rpi-dns.sh` | — | installs everything, restarts dnsmasq, prints the bind view |
`lab-internal.hosts` is installed **outside** `/etc/dnsmasq.d` because the
systemd unit parses every file in that directory as config (`-7
/etc/dnsmasq.d`); a hosts file there aborts the start with `bad option`.
## Install / update (root on rpi)
```bash
bash install-rpi-dns.sh
```
## Add a record
```bash
# 1. edit lab-internal.hosts in git and commit, then on rpi:
sudo install -m 0644 lab-internal.hosts /etc/dnsmasq-lab-internal.hosts
sudo systemctl reload dnsmasq # re-reads addn-hosts, no restart
dig +short grafana.lab.internal @10.10.0.1
```
## Verify
```bash
sudo ss -lntuH 'sport = :53' # 127.0.0.1, 10.10.0.1, 10.20.0.2, [::1] only
sudo iptables -L ufw-user-input -n -v | grep dpt:53
# from a WireGuard client (not on the LAN):
dig +short grafana.lab.internal @10.10.0.1 # 10.10.0.2
dig +short example.com @10.10.0.1 # forwards, public answer
# negative, from the LAN: must time out (DROP)
dig +time=3 grafana.lab.internal @192.168.1.125
```
## Why the client must use `10.10.0.1` as its DNS
Android/iOS apply the tunnel's DNS as the resolver for the **whole device**
while the tunnel is up — there is no per-domain split. This resolver therefore
answers `lab.internal` locally and forwards everything else upstream, so public
DNS keeps working. Clearing the field in the WireGuard app is the rollback.

View file

@ -0,0 +1,21 @@
#!/bin/bash
# Install the lab.internal resolver on rpi (the WireGuard hub).
# Run as root from a checkout of sirius/homek8s:
# bash infrastructure/networking/internal/dns/install-rpi-dns.sh
#
# Re-run after a Pi reinstall or after editing the records. Idempotent.
set -euo pipefail
cd "$(dirname "$0")"
install -m 0644 lab-internal.conf /etc/dnsmasq.d/lab-internal.conf
install -m 0644 lab-internal.hosts /etc/dnsmasq-lab-internal.hosts
bash rpi-ufw-dns.sh
# dnsmasq is already enabled at boot on rpi; make that explicit, not assumed.
systemctl enable dnsmasq
systemctl restart dnsmasq
sleep 1
systemctl is-active dnsmasq
ss -lntup | grep ':53 ' || true

View file

@ -0,0 +1,35 @@
# dnsmasq drop-in for the WireGuard-only resolver on rpi (the WG hub).
# Installed as /etc/dnsmasq.d/lab-internal.conf by install-rpi-dns.sh.
#
# WHY: WireGuard clients (Android/iOS especially) apply the tunnel's DNS as the
# resolver for the WHOLE device while the tunnel is up -- there is no per-domain
# split on the client. So this server must answer the internal zone itself and
# FORWARD everything else upstream, otherwise turning it on breaks public DNS.
#
# Zone: lab.internal only. Never squat .internal bare or home.arpa.
# Authoritative for lab.internal: never forward it upstream, answer from the
# records below and NXDOMAIN for anything else in the zone.
local=/lab.internal/
# Records live in a plain hosts(5) file -- add a service by adding one line
# there (infrastructure/networking/internal/dns/lab-internal.hosts).
addn-hosts=/etc/dnsmasq-lab-internal.hosts
# Listen ONLY on loopback and the two WireGuard interfaces. bind-dynamic lets a
# missing/down WireGuard interface come and go without restarting dnsmasq.
# The hub's LAN address (192.168.1.125) must NOT serve DNS; ufw enforces that
# too, but not binding it at all is the first line.
bind-dynamic
interface=lo
interface=wg0
interface=wg-remote
# Forwarding: inherited from /etc/resolv.conf, which on rpi is generated by
# tailscale (100.100.100.100 = MagicDNS, which forwards to the DHCP resolvers).
# Do not hardcode a public resolver here.
# Don't forward single-label names or reverse-lookups for RFC1918 we own; keeps
# LAN/mDNS noise off the upstream and out of the public root.
domain-needed
bogus-priv

View file

@ -0,0 +1,10 @@
# lab.internal zone records -- hosts(5) syntax: <address> <name> [aliases]
# Installed as /etc/dnsmasq.d/lab-internal.hosts, read by dnsmasq via
# addn-hosts=. Adding a service = adding a line here + `systemctl reload dnsmasq`
# on rpi (a reload re-reads addn-hosts; no restart needed).
#
# 10.10.0.2 is siriussec, which serves both internal dashboards today (Cilium
# ingress Envoy is only on siriussec; 10.10.0.1/rpi does not front them). If
# the gateway ever moves to rpi, change the address here only.
10.10.0.2 grafana.lab.internal
10.10.0.2 hubble.lab.internal

View file

@ -0,0 +1,35 @@
#!/bin/bash
# rpi: keep the WireGuard resolver CLOSED to everything but the VPN.
#
# dnsmasq is already the Pi's resolver service (it also serves the .rpi.local
# alias), and ufw on rpi has `allow from 192.168.1.0/24` (any port), so a plain
# `ufw deny 53` would append BELOW that catch-all and never match. Everything
# here is `ufw insert`, which puts the rule at the top of the user chain.
#
# Final order: allow from the mesh (10.10.0.0/24), the remote hub
# (10.20.0.0/24) and the pod CIDR; then deny 53 for everyone else. Loopback is
# already accepted by ufw's before-input chain, and lab-internal.conf binds
# only lo/wg0/wg-remote anyway -- this is the belt to that braces.
#
# Run as root on rpi (192.168.1.125). Idempotent: re-running only adds missing
# rules.
set -euo pipefail
if ufw status | grep -q 'wg-dns'; then
echo "dns rules already present:"
ufw status | grep -E '53/(udp|tcp)'
exit 0
fi
# Denies first, then the allows are inserted above them.
ufw insert 1 deny 53/udp comment 'wg-dns: resolver is VPN only'
ufw insert 1 deny 53/tcp comment 'wg-dns: resolver is VPN only'
for proto in udp tcp; do
ufw insert 1 allow from 10.10.0.0/24 to any port 53 proto "$proto" comment 'wg-dns (mesh)'
ufw insert 1 allow from 10.20.0.0/24 to any port 53 proto "$proto" comment 'wg-dns (remote hub)'
ufw insert 1 allow from 10.244.0.0/16 to any port 53 proto "$proto" comment 'wg-dns (pods)'
done
echo "dns rules installed:"
ufw status | grep -E '53/(udp|tcp)' || true