conntrack is the connection tracking subsystem of netfilter in the Linux kernel, together with the userspace command of the same name that lists, monitors and deletes its entries. In Linux networking, conntrack is what turns a packet filter into a stateful firewall: it remembers every flow that crosses the host so that rules can match packets by connection state rather than by headers alone.
The kernel side lives in the nf_conntrack module and is used by iptables, nftables, firewalld and UFW alike. The userspace side, shipped in the conntrack-tools package, talks to the kernel through the ctnetlink interface and is the standard way to inspect the state table on a running system.
How connection tracking records flows
When the first packet of a flow arrives, conntrack creates an entry keyed by a tuple of addresses, ports and protocol. Each entry stores two directions, the original tuple and the reply tuple, so that a returning packet is recognized as part of the same connection even when NAT has rewritten its addresses.
Entries are kept in a hash table in kernel memory, sized by nf_conntrack_buckets and capped by nf_conntrack_max. Each entry carries a protocol-specific timeout that is refreshed by matching traffic; when it expires, the entry is removed and later packets are treated as a new flow.
Firewall rules see a simplified connection state for every packet. The following table describes the states that rules can match with ct state in nftables or --ctstate in iptables.
| State | Meaning | Typical rule decision |
|---|---|---|
| NEW | First packet of a flow not yet confirmed | Accept only for allowed services |
| ESTABLISHED | Packets seen in both directions | Accept early in the rule set |
| RELATED | New flow linked to an existing one | Accept, for example ICMP errors |
| INVALID | Packet that fits no valid flow | Drop |
| UNTRACKED | Packet exempted from tracking | Handle with explicit rules |
For TCP, conntrack additionally follows the protocol state machine with internal states such as SYN_SENT, ESTABLISHED, FIN_WAIT and TIME_WAIT. These internal states are what the userspace tool displays, and they decide which timeout applies to an entry.
Working with the conntrack command
The conntrack command gives administrators direct read and write access to the kernel table. It is far more precise than reading /proc/net/nf_conntrack, because it supports filters, event streams and deletion.
The table below lists the operations used most often in troubleshooting.
| Command | Purpose | Practical note |
|---|---|---|
| conntrack -L | List all tracked entries | Add -p tcp –dport 443 to filter |
| conntrack -E | Stream new, updated and destroyed events | Ideal for watching flows live |
| conntrack -D | Delete matching entries | Forces flows to be reevaluated |
| conntrack -F | Flush the whole table | Disrupts NAT flows; use with care |
| conntrack -C | Print the current entry count | Compare with nf_conntrack_max |
| conntrack -S | Show per-CPU statistics | Reveals drops, inserts and searches |
Deleting entries is often necessary after a firewall or NAT change, because existing flows keep their original translation until their entry expires. A long-lived UDP stream, for example, can continue using an outdated NAT mapping until it is removed with conntrack -D.
Timeouts and table sizing
Timeouts determine how long idle flows occupy memory, and they are tunable through sysctl keys under net.netfilter. Defaults differ between kernel versions, so the values below are typical rather than guaranteed.
| Sysctl parameter | Typical default | Applies to |
|---|---|---|
| nf_conntrack_tcp_timeout_established | 432000 s (5 days) | Idle established TCP connections |
| nf_conntrack_tcp_timeout_time_wait | 120 s | TCP connections after close |
| nf_conntrack_udp_timeout | 30 s | UDP flows seen in one direction |
| nf_conntrack_udp_timeout_stream | 120 to 180 s | UDP flows seen in both directions |
| nf_conntrack_icmp_timeout | 30 s | ICMP echo exchanges |
The five-day TCP default is generous and can fill the table on busy NAT gateways with many abandoned connections. Lowering it, and raising nf_conntrack_max in proportion to available memory, is a standard tuning step for load balancers and container hosts.
Relationship to NAT, helpers and related tools
Network address translation in Linux depends entirely on conntrack. The NAT decision is made once, on the first packet of a flow, and stored in the conntrack entry; all later packets are rewritten from that stored mapping without consulting the NAT rules again.
Connection tracking helpers extend the system for protocols such as FTP and SIP that negotiate extra ports inside their payload. Since kernel 4.7, automatic helper assignment is disabled by default, so helpers must be attached explicitly with ct helper rules, which closes a known abuse path.
Several neighboring components are often confused with conntrack, as the following comparison shows.
| Component | Role | Relation to conntrack |
|---|---|---|
| netfilter | Kernel packet filtering framework | Hosts conntrack as one of its modules |
| nftables | Rule language and kernel tables | Matches ct state, ct mark and ct zone |
| iptables | Legacy rule front end | Uses the conntrack and state matches |
| conntrackd | Synchronization daemon | Replicates entries between firewall nodes |
| tcpdump | Packet capture tool | Shows packets, not tracked flow state |
Limitations and failure modes
The most familiar failure is the kernel message table full, dropping packet, which appears when the entry count reaches nf_conntrack_max. New flows are then silently dropped, which looks like random connection failures to users while existing flows continue to work.
- Memory cost: every entry consumes kernel memory, so very large tables need RAM planning.
- DDoS exposure: SYN floods and UDP floods create entries quickly and can exhaust the table.
- Asymmetric routing: replies that bypass the host make flows look INVALID and get dropped.
- Stale NAT mappings: rule changes do not affect flows that are already tracked.
High-volume stateless traffic, such as authoritative DNS, is often exempted with notrack rules in the raw table or an nftables prerouting chain. This removes the tracking cost entirely but also removes stateful protection for that traffic, so it must be filtered by explicit rules.
Put simply
conntrack is the memory of a Linux firewall. Every time a computer starts a conversation over the network, conntrack writes it down, so that when the answer comes back the firewall knows it was expected and lets it through.
It works like a receptionist with a visitor log. Guests who were invited get waved in, unknown arrivals are checked against the rules, and old entries are crossed out after a while. If the log runs out of pages, new visitors are turned away until space frees up.
In practice
An operations engineer runs a Linux NAT gateway that serves about 4,000 office and guest devices. Users begin reporting that some websites fail to load at peak hours, while ongoing video calls continue normally. The kernel log shows the table full message, and conntrack -C returns 262,144, exactly the configured nf_conntrack_max.
Running conntrack -L reveals that most entries are idle established TCP flows left by mobile devices that disconnected without closing their sessions. The engineer lowers the established timeout from five days to two hours, raises the table limit to 524,288 after checking memory headroom and makes both settings persistent in a sysctl file. Within an hour the entry count stabilizes at about 90,000, and the failures stop.