#!/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