Issue#
A busy server (load balancer, NAT gateway, Docker or Kubernetes node) starts dropping connections at random. Clients see timeouts or slow connects, but CPU, memory and the network link look fine. The kernel log shows:
nf_conntrack: nf_conntrack: table full, dropping packet
Cause#
When netfilter connection tracking is loaded (by iptables/nftables NAT, stateful firewall rules, Docker or kube-proxy), the kernel tracks every connection in the conntrack table. That table has a fixed limit, net.netfilter.nf_conntrack_max. Once it is full, new packets that need a conntrack entry are dropped.
The limit is often too low for high-traffic hosts. Long timeouts make it worse: established TCP entries stay for 5 days by default (nf_conntrack_tcp_timeout_established = 432000), even after a client disappears without closing the connection.
Solution#
- Check the current usage against the limit:
sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max
If the count is at or near the max, the table is full.
- Optionally, inspect drops and the busiest sources (needs the
conntrackpackage):
sudo apt install -y conntrack
sudo conntrack -S | grep -o 'drop=[0-9]*\|insert_failed=[0-9]*'
sudo conntrack -L 2>/dev/null | grep -o 'src=[0-9.]*' | sort | uniq -c | sort -rn | head
- Raise the limit right away (each entry uses about 300 bytes, so 262144 entries is roughly 80 MB):
sudo sysctl -w net.netfilter.nf_conntrack_max=262144
- Lower the established TCP timeout so dead connections are cleaned up sooner:
sudo sysctl -w net.netfilter.nf_conntrack_tcp_timeout_established=86400
- Make the settings persistent. Load the module at boot so the sysctl keys exist when
systemd-sysctlruns:
echo nf_conntrack | sudo tee /etc/modules-load.d/nf_conntrack.conf
sudo tee /etc/sysctl.d/90-conntrack.conf <<'EOF'
net.netfilter.nf_conntrack_max = 262144
net.netfilter.nf_conntrack_tcp_timeout_established = 86400
EOF
sudo sysctl --system
- Size the hash table to match (about
nf_conntrack_max / 4) for faster lookups:
echo 65536 | sudo tee /sys/module/nf_conntrack/parameters/hashsize
echo "options nf_conntrack hashsize=65536" | sudo tee /etc/modprobe.d/nf_conntrack.conf
Tip: On Kubernetes nodes, kube-proxy sets
nf_conntrack_maxitself on startup and can override your sysctl. Tune it with theconntrack.maxPerCoreandconntrack.minfields in the kube-proxy configuration instead (kubectl -n kube-system edit configmap kube-proxy, then restart the kube-proxy pods).
Verify#
Confirm the new values are active:
sysctl net.netfilter.nf_conntrack_max net.netfilter.nf_conntrack_tcp_timeout_established
cat /sys/module/nf_conntrack/parameters/hashsize
Watch usage under load. The count should stay well below the max:
watch -n 2 'sysctl -n net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max'
Make sure no new drop messages appear:
sudo dmesg -T | grep -i "table full"