Stop letting your web server choke on ephemeral port exhaustion

Performance Tuning & Kernel Parameters (Sysctl)

Stop letting your web server choke on ephemeral port exhaustion

🧩 The Challenge

You finally launch a high-traffic app and suddenly the server starts dropping incoming connections like a stone, even though the CPU is barely idling. I wasted an entire afternoon staring at this before realizing the system was simply running out of local ports to talk to the database.

💡 The Fix

Crank up the range of ports the kernel is allowed to use for outgoing connections so you don’t hit that wall during traffic bursts. You should also enable TCP timestamping to let the kernel reuse connections more aggressively.

sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_tw_reuse=1

⚙️ Why It Works

Expanding the port range gives you a much larger buffer before the OS gets picky about available sockets. Flipping the reuse flag allows the kernel to recycle a connection in a time-wait state for new outgoing requests, which saves you from exhausting your ephemeral pool.

🚀 Pro-Tip: Run ss -s to see your current socket stats and check if your local port count is actually creeping toward the ceiling.

Linux Tips & Tricks | © ngelinux.com | 7/23/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted