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

Long-lived connections through a Linux NAT box get reset, and conntrack logs show packets classified as `INVALID`.

AdvancedTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer

Likely causes → Conntrack tracks TCP windows strictly. Packets that fall outside the tracked window (after heavy reordering, a conntrack table restart, or a flow that started before the box took over) are marked INVALID, and a typical ruleset drops them or doesn't NAT them, so they leak with the private source and the peer answers with RST.

Diagnose →

sudo conntrack -S | grep -o 'invalid=[0-9]*'
sudo iptables -L FORWARD -v -n | grep INVALID
sudo sysctl -w net.netfilter.nf_conntrack_log_invalid=6   # log TCP invalids, then check dmesg

Fix → Drop INVALID explicitly so they never leave un-NATed (iptables -A FORWARD -m conntrack --ctstate INVALID -j DROP), and if reordering is expected, set net.netfilter.nf_conntrack_tcp_be_liberal=1 so only out-of-window RSTs count as invalid.

Prevent → Sync conntrack state between HA NAT nodes (conntrackd) and avoid ECMP paths that reorder single flows.

All Networking questions Roadmap: Networking for DevOps

More on Sockets, ports, TIME_WAIT and conntrack