Performance Tuning & Kernel Parameters (Sysctl)
Taming connection churn with tcp_tw_reuse
đź§© The Challenge
You ever see a web server just tank when it hits a burst of traffic because all your sockets are stuck in TIME_WAIT? It’s a total headache when the kernel won’t recycle those ports fast enough and your app starts throwing connection refused errors.
đź’ˇ The Fix
Enabling the kernel’s ability to reuse these sockets allows the system to pull them back into service for new connections even if they’re still in the final closing stages. It saves your bacon during high-volume spikes.
sysctl -w net.ipv4.tcp_tw_reuse=1
⚙️ Why It Works
Setting this to 1 tells the TCP stack it’s safe to initiate a new connection using a socket currently in TIME_WAIT state if it’s technically secure to do so based on the timestamp. Just don’t get reckless and turn on tcp_tw_recycle, as that causes all sorts of nightmare NAT issues that you won’t want to debug on a Friday night.
🚀 Pro-Tip: Add it to /etc/sysctl.d/99-networking.conf so you don’t lose it after a reboot.
Linux Tips & Tricks | © ngelinux.com | 7/12/2026
