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

Under load, `conntrack -S` shows `insert_failed` climbing, and outbound connections from containers fail sporadically.

AdvancedTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer

Likely causes → A race in SNAT/MASQUERADE: two connections from different containers are assigned the same source port at the same moment; the second conntrack insert fails and the packet is dropped. The client sees a timeout (often 1 s or 5 s extra latency on retry). Very common for high-rate outbound calls and for UDP DNS from pods.

Diagnose →

sudo conntrack -S | grep -o 'insert_failed=[0-9]*'
sudo iptables -t nat -S POSTROUTING | grep MASQUERADE

Fix → Use fully random port allocation on the masquerade rule (--random-fully, which recent Docker, kube-proxy and most CNIs apply), reduce SNAT by using VPC-native pod IPs, and reuse connections with keepalive/pooling. For DNS, use NodeLocal DNSCache or options single-request-reopen.

Prevent → Graph insert_failed per node and include it in node health dashboards.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack