Stop your network sockets from lingering in limbo

Performance Tuning & Kernel Parameters (Sysctl)

Stop your network sockets from lingering in limbo

🧩 The Challenge

You ever look at a busy web server and see thousands of connections stuck in TIME_WAIT? It makes your ephemeral port range disappear, and suddenly the app starts throwing errors because it can’t open a new socket.

💡 The Fix

Flip a couple of kernel parameters to let the OS recycle those connections faster. It basically tells the kernel to stop babying the dead sockets and move on so your app gets the ports it needs.

sysctl -w net.ipv4.tcp_tw_reuse=1
sysctl -w net.ipv4.tcp_fin_timeout=15

⚙️ Why It Works

Setting reuse to 1 allows the kernel to safely reuse a socket in the TIME_WAIT state for a new outgoing connection, which is a lifesaver under high load. Dropping the fin timeout forces the stack to close those connections twice as fast as the default 60 seconds.

🚀 Pro-Tip: Don’t forget to make these changes permanent in /etc/sysctl.conf unless you want to do this again after a reboot.

Linux Tips & Tricks | © ngelinux.com | 12/6/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted