diff --git a/README.md b/README.md index bd06ff8..3a306ad 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,28 @@ Alternatives: `ENABLE_MDNS=true` + `BASE_DOMAIN=*.local` (zero-config mDNS, macOS/Linux native, Windows needs Bonjour) — but mDNS can't serve the air-gap upstream spoofs. Or layer in `docker-compose.dnsmasq.yml` for a turnkey DNS. +### Simulate the DNS via /etc/hosts (single machine, testing) + +No DNS server? Append the records straight to `/etc/hosts` (marker-wrapped): + +```sh +tooling/dns-records.sh online hosts | sudo tee -a /etc/hosts # services only +tooling/dns-records.sh airgap hosts | sudo tee -a /etc/hosts # + Mojang spoofs +``` + +Remove them later: + +```sh +sudo sed -i '/# >>> ulicraft/,/# <<< ulicraft/d' /etc/hosts +``` + +Notes: +- `/etc/hosts` has **no wildcard** — only the listed names resolve. +- `airgap` adds the Mojang/launcher/NeoForge hostnames pointing at the LAN; this + **breaks normal internet access to those domains** while present. Use it only + while offline; for an online box use `online`. +- `mc.` works (client defaults to :25565); SRV isn't used via `/etc/hosts`. + ## Prerequisites Docker + Docker Compose; for prep also `pnpm`, `packwiz`, `jq`, `curl`, diff --git a/tooling/dns-records.sh b/tooling/dns-records.sh index ac53ca9..ce49e36 100755 --- a/tooling/dns-records.sh +++ b/tooling/dns-records.sh @@ -40,9 +40,21 @@ names=("${services[@]}") case "$mode" in online) ;; airgap) names+=("${spoof[@]}") ;; - *) echo "usage: $0 [online|airgap]" >&2; exit 1 ;; + *) echo "usage: $0 [online|airgap] [hosts]" >&2; exit 1 ;; esac +# Marker so /etc/hosts edits can be applied/removed cleanly. +MARK="ulicraft ${mode}" + +# `hosts` format: print ONLY the /etc/hosts block (marker-wrapped) so it can be +# piped straight into /etc/hosts to simulate the party DNS. See README. +if [ "${2:-}" = hosts ]; then + echo "# >>> ${MARK} >>>" + for n in "${names[@]}"; do printf '%s %s\n' "$HOST_LAN_IP" "$n"; done + echo "# <<< ${MARK} <<<" + exit 0 +fi + echo "# DNS records for mode=${mode} -> ${HOST_LAN_IP}" echo "# Configure these on your party DNS server (all A records to the host)." echo