Interview Prep/Networking/Sockets, ports, TIME_WAIT and conntrack

After a DNS server behind a UDP load-balancing iptables rule was replaced, some clients keep failing lookups for minutes.

AdvancedTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer

Likely causes → UDP has no close, so conntrack keeps the existing DNAT mapping (client IP:port → old backend) alive as long as packets keep arriving within nf_conntrack_udp_timeout_stream (120 s by default, refreshed on each packet). Clients reusing the same source port are pinned to the dead backend. Kubernetes hit the same issue with CoreDNS pod replacement.

Diagnose →

sudo conntrack -L -p udp --dport 53 | grep <old-backend-ip>
sysctl net.netfilter.nf_conntrack_udp_timeout net.netfilter.nf_conntrack_udp_timeout_stream

Fix → Flush stale entries for the old backend:

sudo conntrack -D -p udp --orig-dst <vip> --dport 53
sudo conntrack -D -p udp --reply-src <old-backend-ip>

Prevent → Make backend changes clear conntrack automatically (kube-proxy does this for UDP endpoints), shorten UDP timeouts on DNS-heavy nodes, or use NodeLocal DNSCache so clients talk to a stable local IP.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack