conntrack on Linux: Reading the Table, Timeouts, and Reproducing "nf_conntrack: table full, dropping packet"
Every stateful Linux firewall, NAT gateway and container host leans on connection tracking, and almost nobody looks at it until it fails. The failure has a famous log line: nf_conntrack: table full, dropping packet. By then new connections are timing out and the box looks otherwise healthy.
I built a small router on my Debian 13 test VM, read its table, then deliberately filled it. Everything below is real output.
The lab
Three network namespaces in a line: a client, a router and a server. The router forwards and runs a simple stateful nftables policy.
sudo apt install conntrack nftables python3
for n in cl rt sv; do sudo ip netns add $n; done
sudo ip link add c0 type veth peer name r0
sudo ip link add s0 type veth peer name r1
sudo ip link set c0 netns cl; sudo ip link set r0 netns rt
sudo ip link set r1 netns rt; sudo ip link set s0 netns sv
sudo ip -n cl addr add 10.10.1.2/24 dev c0
sudo ip -n rt addr add 10.10.1.1/24 dev r0
sudo ip -n rt addr add 10.10.2.1/24 dev r1
sudo ip -n sv addr add 10.10.2.2/24 dev s0
for l in "cl c0" "cl lo" "rt r0" "rt r1" "sv s0" "sv lo"; do set -- $l; sudo ip -n $1 link set $2 up; done
sudo ip -n cl route add default via 10.10.1.1
sudo ip -n sv route add default via 10.10.2.1
sudo ip netns exec rt sysctl -w net.ipv4.ip_forward=1
The router’s firewall only lets the client side start connections:
table inet fw {
chain forward {
type filter hook forward priority 0; policy drop;
ct state established,related accept
ct state new ip saddr 10.10.1.0/24 accept
}
}
Referencing ct state is what loads connection tracking into that namespace. No rule that mentions conntrack, no tracking.
Reading the table
I opened a TCP connection from the client to a throwaway Python server and closed it. Then, on the router:
$ sudo ip netns exec rt conntrack -L
tcp 6 119 TIME_WAIT src=10.10.1.2 dst=10.10.2.2 sport=44052 dport=8080 src=10.10.2.2 dst=10.10.1.2 sport=8080 dport=44052 [ASSURED] mark=0 use=1
conntrack v1.4.8 (conntrack-tools): 1 flow entries have been shown.
Reading it left to right:
| Field | Meaning |
|---|---|
tcp 6 | protocol name and number |
119 | seconds until this entry expires |
TIME_WAIT | TCP state as the tracker sees it |
first src= dst= sport= dport= | the original direction |
second src= dst= sport= dport= | what the reply is expected to look like |
[ASSURED] | traffic has been seen both ways, so the entry is not an early-drop candidate |
[UNREPLIED] | (not shown here) only one direction seen |
The second tuple is why NAT works. With source NAT the reply tuple is the part that gets rewritten, and the kernel uses it to translate return traffic.
You can also watch entries being born and updated in real time:
$ sudo ip netns exec rt conntrack -E
[NEW] icmp 1 30 src=10.10.1.2 dst=10.10.2.2 type=8 code=0 id=55922 [UNREPLIED] src=10.10.2.2 dst=10.10.1.2 type=0 code=0 id=55922
[UPDATE] icmp 1 30 src=10.10.1.2 dst=10.10.2.2 type=8 code=0 id=55922 src=10.10.2.2 dst=10.10.1.2 type=0 code=0 id=55922
The [UNREPLIED] flag disappears on the update when the echo reply arrives. Useful for proving whether return traffic is making it back.
sudo conntrack -C prints the current count. /proc/net/nf_conntrack has the same data without the tool installed.
The limits and timeouts that matter
$ sudo sysctl net.netfilter.nf_conntrack_max net.netfilter.nf_conntrack_buckets \
net.netfilter.nf_conntrack_tcp_timeout_established \
net.netfilter.nf_conntrack_tcp_timeout_time_wait \
net.netfilter.nf_conntrack_udp_timeout \
net.netfilter.nf_conntrack_udp_timeout_stream \
net.netfilter.nf_conntrack_icmp_timeout
net.netfilter.nf_conntrack_max = 65536
net.netfilter.nf_conntrack_buckets = 65536
net.netfilter.nf_conntrack_tcp_timeout_established = 432000
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 120
net.netfilter.nf_conntrack_udp_timeout = 30
net.netfilter.nf_conntrack_udp_timeout_stream = 120
net.netfilter.nf_conntrack_icmp_timeout = 30
Those are the defaults on a 2 GB Debian 13 VM. The one that surprises people is the established TCP timeout: 432000 seconds, which is five days. A connection that dies without a FIN or RST (a client that lost power, a NAT mapping that expired upstream) occupies a slot for up to five days. On a busy gateway that is how a table fills slowly with ghosts. Lowering it to a few hours is a common change, as long as your applications send keepalives within that window.
Each entry costs memory. /proc/slabinfo reports the object size on this kernel:
$ sudo grep -E "^nf_conntrack " /proc/slabinfo | awk '{print "objsize="$4" bytes"}'
objsize=256 bytes
At 256 bytes, the 65,536 default is roughly 16 MB of entries. Raising the limit is cheap in memory terms. Raising it without understanding why the table is filling is just postponing the incident.
One surprise: the limit is not per namespace
My first attempt to set a tiny limit inside the router namespace failed:
$ sudo ip netns exec rt sysctl -w net.netfilter.nf_conntrack_max=100
sysctl: setting key "net.netfilter.nf_conntrack_max": Operation not permitted
Even as root, a network namespace cannot change nf_conntrack_max. It can read the value, but it is set from the initial namespace. The count is per namespace, the ceiling is global. That matters for container hosts: one noisy container’s table is bounded by the host’s setting, not its own.
I set it on the host for the test and restored it afterwards.
Reproducing “table full”
sudo sysctl -w net.netfilter.nf_conntrack_max=100
Then 300 UDP datagrams from 300 different source ports, which creates 300 distinct flows:
import socket
for i in range(300):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('10.10.1.2', 21000 + i))
s.sendto(b'x', ('10.10.2.2', 9000))
s.close()
$ sudo ip netns exec rt conntrack -C
100
$ sudo ip netns exec rt conntrack -S
cpu=0 found=0 invalid=0 insert=0 insert_failed=0 drop=195 early_drop=5 error=0 ...
cpu=1 found=0 invalid=0 insert=0 insert_failed=0 drop=0 early_drop=0 error=0 ...
and in the kernel log:
nf_conntrack: nf_conntrack: table full, dropping packet
Count it up: 300 sent, 100 tracked, 195 dropped, 5 early-dropped. When the table is full the kernel first tries to evict an old entry that has not been confirmed as a two-way flow (early_drop), and if it cannot make room it drops the new packet (drop). The [ASSURED] flag from earlier is exactly what protects established flows from eviction.
Then the part that hurts. With the table full I tried a brand new TCP connection through the router:
client: timed out 4.0 s
server: no connection ( timed out )
The SYN never reached the server. No RST, no ICMP error, just a hang. From the application’s side this is indistinguishable from a dead server, which is why the first hour of this incident is usually spent looking at the wrong box.
What to watch
sudo conntrack -Cagainstsysctl net.netfilter.nf_conntrack_max. Alert at 80%.sudo conntrack -S. A risingdroporinsert_failedis the counter that confirms it, before anyone reads a log.dmesg | grep conntrack, which only helps after the fact.- A top-talker breakdown, to find out who is filling it:
sudo conntrack -L 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i ~ /^src=/){print $i; break}}' | sort | uniq -c | sort -rn | head
In the test that printed 300 src=10.10.1.2, one client, which is the shape of a scan, a leaky application or a DNS loop.
Fixing it properly
- Find the source first (above). A single misbehaving host is a cheaper fix than a bigger table.
- Lower timeouts that are too generous, particularly
tcp_timeout_establishedandudp_timeout_stream. - Exempt traffic that does not need state with a
notrackrule in arawpriority chain, for example high-volume DNS to a local resolver. - Only then raise
nf_conntrack_max.
To persist a change on Debian, drop a file in /etc/sysctl.d/:
echo 'net.netfilter.nf_conntrack_max = 262144' | sudo tee /etc/sysctl.d/90-conntrack.conf
sudo sysctl --system
One catch: the conntrack sysctls only exist once the module is loaded, so on a box that loads it late the file may not apply at boot. Check with sysctl net.netfilter.nf_conntrack_max after a reboot.
Verdict
The table is a plain finite resource, and the evidence of exhaustion is in three places: a count against a limit, a drop counter, and one kernel log line. Knowing where to look turns a mystery outage into a two minute diagnosis.