`dmesg` is full of `nf_conntrack: nf_conntrack: table full, dropping packet` and new connections randomly time out.
IntermediateTroubleshootingSockets, ports, TIME_WAIT and conntrack
Answer
Likely causes → The conntrack table hit nf_conntrack_max. Every tracked flow (including short DNS and health-check flows) holds an entry until its timeout expires, so a traffic spike, a scan, or long TIME_WAIT/UDP timeouts fill it. When full, the kernel drops new flows silently, which looks like random timeouts.
Diagnose →
sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max
sudo conntrack -S | head # look at drop / early_drop counters
sudo conntrack -L -o extended | awk '{print $3}' | sort | uniq -c | sort -rn # by protocol
sudo conntrack -L | awk '{print $5}' | sort | uniq -c | sort -rn | head # top sources
Fix → Raise the limit and the hash size together, and shorten timeouts for flows you don't need held long:
sudo sysctl -w net.netfilter.nf_conntrack_max=524288
echo 131072 | sudo tee /sys/module/nf_conntrack/parameters/hashsize
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
For high-volume stateless traffic (e.g. a DNS server), exempt it with iptables -t raw -A PREROUTING -p udp --dport 53 -j NOTRACK.
Prevent → Persist values in /etc/sysctl.d/, export nf_conntrack_count / nf_conntrack_max to monitoring and alert at 75%.
More on Sockets, ports, TIME_WAIT and conntrack
`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.AdvancedA blog post told you to set `net.ipv4.tcp_tw_recycle=1`, but `sysctl` returns `cannot stat /proc/sys/net/ipv4/tcp_tw_recycle`.Beginner