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:
parent
48b2b6ac01
commit
ead60fface
6 changed files with 365 additions and 0 deletions
56
infrastructure/networking/internal/dns/README.md
Normal file
56
infrastructure/networking/internal/dns/README.md
Normal 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.
|
||||
21
infrastructure/networking/internal/dns/install-rpi-dns.sh
Executable file
21
infrastructure/networking/internal/dns/install-rpi-dns.sh
Executable 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
|
||||
35
infrastructure/networking/internal/dns/lab-internal.conf
Normal file
35
infrastructure/networking/internal/dns/lab-internal.conf
Normal 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
|
||||
10
infrastructure/networking/internal/dns/lab-internal.hosts
Normal file
10
infrastructure/networking/internal/dns/lab-internal.hosts
Normal 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
|
||||
35
infrastructure/networking/internal/dns/rpi-ufw-dns.sh
Executable file
35
infrastructure/networking/internal/dns/rpi-ufw-dns.sh
Executable 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
|
||||
Loading…
Reference in a new issue