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.
More on Sockets, ports, TIME_WAIT and conntrack
`dmesg` is full of `nf_conntrack: nf_conntrack: table full, dropping packet` and new connections randomly time out.Intermediate`ss -s` on a reverse proxy shows 40,000 sockets in `TIME_WAIT`. Is that a problem?BeginnerAn app server's `CLOSE_WAIT` count grows steadily until the service logs `Too many open files`.IntermediateLogs show `accept4(): Too many open files` and the service stops accepting connections.Beginner`dmesg` shows `TCP: request_sock_TCP: Possible SYN flooding on port 443. Sending cookies.`Intermediate`ss -ltn` shows the listener for port 8080 with `Recv-Q 129` and `Send-Q 128`, and clients hang on connect.Advanced