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
35 lines
1.5 KiB
Shell
Executable file
35 lines
1.5 KiB
Shell
Executable file
#!/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
|