Conntrack: how Linux remembers every network connection

Updated November 1, 2026

The Linux kernel subsystem that remembers every active connection. Without it NAT cannot route a reply back to the right private IP, and a firewall cannot tell a "new connection" from an "already established" one. You see it in /proc/net/nf_conntrack.

Why you need it

When your router does NAT, it rewrites the src IP/port of an outgoing packet. The reply from the server arrives at the router's public IP, and the router must route it back to the correct private IP inside the LAN.

For this to work, the router has to remember every active connection: which internal host, which external one, which ports, which protocol. That memory is conntrack (connection tracking).

Without conntrack:

  • NAT would work in one direction only (outgoing yes, reply no way)
  • a stateful firewall would be impossible (you cannot tell a "new SYN" from an "already established connection")

What a record holds

Each tracked connection = one record with these fields:

  • protocol: TCP/UDP/ICMP/...
  • original direction: src IP+port, dst IP+port
  • reply direction: the same for the return packet (after NAT)
  • state: for TCP, NEW / ESTABLISHED / RELATED / INVALID
  • timeout: how much longer it lives with no traffic

See it live:

$ sudo conntrack -L | head
tcp  6 431999 ESTABLISHED src=192.168.1.50 dst=8.8.8.8 \
     sport=54321 dport=443 src=8.8.8.8 dst=80.10.20.30 \
     sport=443 dport=54321 [ASSURED]

Reading it:

  • tcp 6 is TCP, protocol no. 6
  • 431999 is seconds until timeout (about 5 days for ESTABLISHED)
  • ESTABLISHED is the state from the TCP state machine
  • src=192.168.1.50 ... dst=8.8.8.8 is the original direction
  • src=8.8.8.8 ... dst=80.10.20.30 is the reply direction (notice how dst changed to the public IP, that is the trace of NAT)

States

For TCP:

StateMeaning
NEWSaw the first packet only (SYN)
ESTABLISHEDTwo-way exchange confirmed
RELATEDTied to another connection (FTP-data to FTP-control)
INVALIDAbnormal packet that did not fit anywhere

These states are the basis for iptables -m state / nft ct state rules. For example, "allow ESTABLISHED+RELATED only" is a standard firewall rule.

Timeouts

Conntrack does not keep a connection forever. There are per-state timeouts:

/proc/sys/net/netfilter/nf_conntrack_tcp_timeout_established  = 432000  # 5 days
/proc/sys/net/netfilter/nf_conntrack_tcp_timeout_close_wait   = 60      # 1 min
/proc/sys/net/netfilter/nf_conntrack_udp_timeout              = 30      # UDP

If a connection closed "dirty" (without FIN), it lingers in conntrack as a zombie for a long time.

Limit and overflow

The conntrack table is bounded (nf_conntrack_max, default about 64K-256K). When it fills up:

  • new connections are dropped (or run untracked, depending on the version)
  • dmesg logs nf_conntrack: table full, dropping packet

On high-traffic servers this is a real problem, so people tune it:

sudo sysctl -w net.netfilter.nf_conntrack_max=1048576

When you do NOT need conntrack

  • On routers with NAT it is required
  • On stateful firewalls it is required
  • On a "dumb" router with no NAT and no firewall you can turn it off (with -j NOTRACK rules) to save CPU and memory. On high-traffic edge routers that is a serious boost

Commands

  • sudo conntrack -L: All active tracked connections
  • sudo conntrack -L -p tcp --dport 443: HTTPS connections only
  • sudo conntrack -E: Realtime events: records created/updated/deleted
  • sudo conntrack -F: Flush the whole table, it rebuilds from live packets
  • cat /proc/sys/net/netfilter/nf_conntrack_count: How many records there are right now
  • cat /proc/sys/net/netfilter/nf_conntrack_max: The limit. If current approaches it, time to tune

See also