Skip to content

Lesson 18 of 18 · 20m

Connection State That Exhausts: conntrack, TIME_WAIT, and Backlogs

nf_conntrack tables fill silently, TIME_WAIT burns ~480 connections/second of ephemeral ports, and accept-queue overflows drop handshakes without errors.

The alert is one line in dmesg: nf_conntrack: table full, dropping packet. From that moment the host silently drops packets — new connections stall, existing ones flap — while CPU, memory, and application logs all look healthy. Connection tracking is a subsystem nobody configures until it becomes the outage.

What conntrack is and why it fills

Every packet through netfilter gets a nf_conntrack entry — the stateful machinery behind NAT and ct state established rules in iptables/nftables/firewalld. The table is finite (net.netfilter.nf_conntrack_max, sized at boot from RAM) and entries live as long as the kernel believes the flow lives: TCP tracks through FIN/RST; UDP gets 120 s timeouts (180 s once "assured") because UDP has no close. High-rate UDP — DNS forwarding, metrics floods, health checks — grows the table; a SYN flood grows it on purpose, which is half the DDoS playbook.

Check it before it checks you: /proc/sys/net/netfilter/nf_conntrack_count against nf_conntrack_max, and conntrack -S for insert-failure counters. The fix isn't always "raise the max." The honest options: raise the table, shorten UDP timeouts, or mark trusted flows NOTRACK in the raw table so they never consume entries. Each costs something — roughly 300 bytes of RAM per entry, correctness under churn, or visibility into the flows you exempted.

TIME_WAIT: the 60 seconds you can't tune away

Whichever side closes a TCP connection first owns TIME_WAIT: the socket lingers ~60 s — a compiled constant (TCP_TIMEWAIT_LEN) — so late segments and retransmits can't leak into a reused four-tuple. It is not governed by tcp_fin_timeout, a persistent myth; that sysctl covers FIN_WAIT_2.

The load that breaks: a client hammering short-lived connections burns one ephemeral port per connection for a full minute after close. With the default ip_local_port_range of 32768–60999 — ~28k ports — the sustained ceiling is roughly 480 connections per second to one destination. Load balancers and hot API clients hit it long before CPU does.

The wrong reflex is tcp_tw_reuse: it recycles a TIME_WAIT's four-tuple when timestamps prove safety, but it's sysctl-wide and helps only the connecting side, not the listener that closed early. The real fixes are architectural:

  • Close on the side that can afford it. Proxies close first so app servers don't hold state; calling connection.close() on your client puts the cost on it.
  • Reuse beats churn. HTTP keep-alive and pooling amortize one socket over thousands of requests — that's the actual reason keep-alive exists, not latency.
  • Widen ip_local_port_range when you genuinely need churn capacity — knowing you've traded away TIME_WAIT's protection against stale segments.

The other quiet exhaustion modes

  • Backlog overflow. somaxconn and the accept queue bound handshakes waiting for accept(); overflow drops them with no error on the listener. ss -ltn shows Send-Q depth against configured backlog; nstat -az TcpExtListenOverflows counts the damage.
  • Middlebox NAT limits. CGNAT and cloud NAT gateways cap per-host flows; one app opening thousands of concurrent flows looks identical to a port scan and gets capped the same way.
  • Keepalive lies. tcp_keepalive_time defaults to 7200 s — two hours before the kernel notices a dead peer on an idle connection. Dead-connection detection at useful timescales is the application's job, not TCP's.

Try this

cat /proc/sys/net/netfilter/nf_conntrack_count /proc/sys/net/netfilter/nf_conntrack_max
conntrack -S 2>/dev/null || dmesg | grep nf_conntrack
ss -s                                     # totals incl. timewait
ss -tan state time-wait | wc -l
nstat -az | grep -E "ListenOverflows|SyncookiesSent"
sysctl net.ipv4.ip_local_port_range net.ipv4.tcp_tw_reuse

Field notes

  • ss -s prints a timewait counter — when it climbs into the tens of thousands during a load test, you've found your port ceiling before your CPU ceiling.
  • Kubernetes nodes NAT nearly everything; conntrack pressure appears on busy nodes first. Cilium's eBPF datapath bypasses conntrack by design for trusted pod traffic.
  • Syncookies absorb SYN floods before conntrack matters — if SyncookiesSent is climbing and the table is filling, you're mid-attack, not mid-load.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.

What is a Web Server? Apache, Nginx, and How the Internet Delivers Web Pages

A web server accepts HTTP requests and returns responses. Apache has been doing this since 1995. Nginx rebuilt the model in 2004 and took over the cloud. Here's how they work, how they differ, and how to pick between them.

Article

How to Install NGINX on Debian & Ubuntu: Server Blocks, HTTPS and Reverse Proxy

When it comes to running a web server for all of my online projects, NGINX is the first that comes to mind for me. By default, it follows my guidelines of running a piece of software – meaning that the software is security-minded, performance-driven, and honestly, really easy to manage all the aspects of it. NGINX is most likely the most popular web server software in the world, and it's well known for being the backbone of some of the biggest sites on the internet to date. It is a lightweight

Article

Minecraft 26.4 Replaced Its Decade-Old Login Crypto. Here's What key-rotation-period-seconds Actually Does.

26.4 Snapshot 9 rewrote how a Java Edition client and server agree on an encryption key. RSA-1024 is out, X25519 is in, and a new key-rotation-period-seconds setting decides how often the server's key changes. I opened the snapshot server jar, timed the login crypto, and checked what changes for...

Article

The Same Researcher Broke apt the Same Way Twice, Seven Years Apart

In 2019 Max Justicz showed apt would install a package an attacker swapped in over a redirect. In November 2026 he did it again, CVE-2026-109518, through a different door that ends in the same place: code as root from a man in the middle. The fix shows how apt reuses files on disk.

Article