Stop your Linux box from hoarding dead connections
Performance Tuning & Kernel Parameters (Sysctl)
Stop your Linux box from hoarding dead connections
🧩 The Challenge
You ever look at a server that’s supposedly idle but its connection table is absolutely packed with TIME_WAIT sockets? I’ve spent way too many Friday nights hunting down ghost connections that weren’t actually doing anything but clogging up the works.
💡 The Fix
Crank up the kernel’s ability to recycle those sockets by tweaking the TCP reuse settings in sysctl. It’s the easiest way to prevent port exhaustion when you’ve got a busy load balancer or a chatty microservice environment.
sysctl -w net.ipv4.tcp_tw_reuse=1
⚙️ Why It Works
Setting this flag tells the kernel it’s safe to reuse an existing connection in the TIME_WAIT state for a new outgoing request. By doing this, you’re essentially letting the box ignore the standard cooldown period because you know the timestamp checks will keep the packets from getting mangled.
🚀 Pro-Tip: Always pair this with a quick check of net.ipv4.ip_local_port_range to make sure you aren’t fighting a narrow port ceiling while you’re at it.
Linux Tips & Tricks | © ngelinux.com | 9/10/2026
