Stop your server from bottlenecking on ephemeral port exhaustion
Performance Tuning & Kernel Parameters (Sysctl)
Stop your server from bottlenecking on ephemeral port exhaustion
🧩 The Challenge
Dealing with a high-traffic API server and suddenly getting connection timeouts that make zero sense? You’ve checked the app logs and the database, but the server just won’t open new sockets fast enough because it’s still stuck in a wait state with thousands of old ones.
💡 The Fix
Crank up the ephemeral port range and enable TCP connection reuse so your server doesn’t sit around waiting for dead sockets to time out. It’s an easy way to stop the “cannot assign requested address” errors that haunt high-concurrency environments.
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_reuse=1
⚙️ Why It Works
Expanding that range gives your kernel way more headroom for outgoing connections, while the reuse flag lets the stack recycle those stubborn sockets trapped in TIME_WAIT much faster than the default settings allow.
🚀 Pro-Tip: Stick these in /etc/sysctl.d/99-networking.conf so they actually survive a reboot instead of just disappearing when the power cycles.
Linux Tips & Tricks | © ngelinux.com | 7/31/2026
