diff --git a/Watchdogs/System/network_watchdog.sh b/Watchdogs/System/network_watchdog.sh index e809025..e502d52 100755 --- a/Watchdogs/System/network_watchdog.sh +++ b/Watchdogs/System/network_watchdog.sh @@ -270,7 +270,17 @@ log "$ICON_SUCCESS Internet reachable" # ============================================================================================== if [[ -n "$DDNS_DOMAIN" ]] && [[ -n "$DDNS_CONTAINER" ]]; then PUBLIC_IP=$(curl -sf --max-time 5 https://ifconfig.me 2>/dev/null | tr -d '[:space:]') - DNS_IP=$(dig +short "$DDNS_DOMAIN" @1.1.1.1 2>/dev/null | grep -Eo '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1) + # dig's failure text names the resolver it could not reach (";; communications error to + # 1.1.1.1#53: timed out"), so scraping its output for an address yields the server, not the + # answer — a guaranteed mismatch that restarts DDNS over what is only a DNS timeout. Trust + # the exit status, and anchor the match so only a bare answer line counts. NXDOMAIN exits 0 + # with no output and correctly falls through to the "could not resolve" branch below. + if DNS_ANSWER=$(dig +short "$DDNS_DOMAIN" @1.1.1.1 2>/dev/null); then + DNS_IP=$(printf '%s\n' "$DNS_ANSWER" \ + | grep -Eox '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' | head -1) + else + DNS_IP="" + fi if [[ -z "$PUBLIC_IP" ]]; then warn "Could not determine public IP — skipping DDNS check"