Stop your TCP stack from recycling ports into oblivion
Performance Tuning & Kernel Parameters (Sysctl)
Stop your TCP stack from recycling ports into oblivion
🧩 The Challenge
Dealing with high-volume web servers that suddenly start throwing connection errors because they ran out of ephemeral ports is a special kind of hell. You end up staring at a wall of TIME_WAIT sockets while the application developer swears the code is clean.
💡 The Fix
Enabling fast reuse of sockets in TIME_WAIT state lets the kernel recycle those dead connections for new ones. It saves you from having to restart services during traffic spikes when your port range is effectively exhausted.
sysctl -w net.ipv4.tcp_tw_reuse=1
⚙️ Why It Works
Setting this flag allows the kernel to safely reuse an existing connection in the TIME_WAIT state for a new one, provided it’s considered safe from a protocol perspective. It prevents your system from hitting a hard wall when it’s under load.
🚀 Pro-Tip: Pair this with a wider ephemeral port range in net.ipv4.ip_local_port_range if you’re still seeing contention.
Linux Tips & Tricks | © ngelinux.com | 10/12/2026
