{"id":1210,"date":"2026-09-23T22:35:17","date_gmt":"2026-09-23T22:35:17","guid":{"rendered":"https:\/\/virtualserversvps.com\/blog\/?p=1210"},"modified":"2026-09-23T22:35:17","modified_gmt":"2026-09-23T22:35:17","slug":"ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps","status":"publish","type":"post","link":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/","title":{"rendered":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">When a busy server starts refusing new connections but traffic and CPU look normal, the cause is often a quiet resource limit: the ephemeral port range, or the loading of SO_REUSEPORT across worker processes. Both show up as connection errors under load and disappear the moment load drops, which makes them easy to misdiagnose as network faults. This guide walks through measuring both, confirming the cause, and widening the limits without opening your box to abuse.<\/p>\n\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Confirm ephemeral port exhaustion<\/h2>\n<!-- \/wp:post-content -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A server handling many outbound connections \u2014 reverse proxies, scrapers, API clients \u2014 consumes ports from the local range. If that range is small, or sockets linger in TIME_WAIT, new outbound connections fail with <code>Cannot assign requested address<\/code>. Check the range and current usage.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>sysctl net.ipv4.ip_local_port_range\nss -s\nss -tan state time-wait | wc -l<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A default range of <code>32768 60999<\/code> gives roughly 28,000 ports. Each connection to a remote host must use a unique local port, so a process opening thousands of short-lived connections per minute can exhaust it. Raise the range and enable socket reuse.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Widen the range and reduce TIME_WAIT pressure<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># \/etc\/sysctl.d\/99-ports.conf\nnet.ipv4.ip_local_port_range = 10000 65535\nnet.ipv4.tcp_tw_reuse = 1\nnet.ipv4.tcp_fin_timeout = 15\nnet.ipv4.tcp_max_tw_buckets = 262144<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Apply and verify.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>sysctl --system\nsysctl net.ipv4.ip_local_port_range net.ipv4.tcp_tw_reuse<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\"><code>tcp_tw_reuse=1<\/code> lets the kernel recycle TIME_WAIT sockets for new outbound connections when it is safe to do so. Since Linux 4.12 it only applies to outbound connections, so it will not disturb state tracking for inbound traffic.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Match the listen backlog to your concurrency<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Kernel restart, overflow behaviour, and the application&#8217;s own accept queue all need to line up. If the accept queue overflows at any level, clients see connection resets under burst load.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># \/etc\/sysctl.d\/99-ports.conf\nnet.core.somaxconn = 4096\nnet.ipv4.tcp_max_syn_backlog = 8192\nnet.ipv4.tcp_abort_on_overflow = 0<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Then set the application&#8217;s listen backlog to the same order of magnitude. In Nginx that is the <code>backlog<\/code> parameter on the <code>listen<\/code> directive; in systemd services, <code>ListenStream<\/code> carries its own backlog.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:table -->\n<figure class=\"wp-block-table\"><table><thead><tr><th>Symptom<\/th><th>Likely cause<\/th><th>Fix<\/th><\/tr><\/thead><tbody><tr><td>&#8220;Cannot assign requested address&#8221;<\/td><td>Ephemeral port exhaustion<\/td><td>Widen ip_local_port_range, enable tw_reuse<\/td><\/tr><tr><td>Connections reset under bursts<\/td><td>Backlog overflow<\/td><td>Raise somaxconn + app backlog<\/td><\/tr><tr><td>Slow new connections, CPU fine<\/td><td>SYN queue drops<\/td><td>Raise tcp_max_syn_backlog<\/td><\/tr><\/tbody><\/table><\/figure>\n<!-- \/wp:table -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Reproduce the failure before changing anything<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A generator that opens outbound connections in a tight loop reproduces port exhaustion on demand and lets you confirm the fix. Run it, watch the error appear, apply the sysctl change, and run it again.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># crude port exhaustion test: open many short-lived connections\nfor i in $(seq 1 40000); do\n  (exec 3&lt;&gt;\/dev\/tcp\/127.0.0.1\/80 2&gt;\/dev\/null &amp;&amp; exec 3&gt;&amp;- 3&lt;&amp;-) 2&gt;\/dev\/null\ndone\necho \"exit $?\"<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Errors such as <code>Cannot assign requested address<\/code> during the run mean the local range or TIME_WAIT handling is the constraint. After widening <code>ip_local_port_range<\/code> and enabling <code>tcp_tw_reuse<\/code>, the same loop completes cleanly.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Second-order effects to check<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:list -->\n<ul class=\"wp-block-list\"><li>Widening the port range lowers the lowest ephemeral port; make sure no local service is already bound in that space, or raise the lower bound above it.<\/li><li>Aggressive <code>tcp_tw_reuse<\/code> does not remove the need for correct TCP timestamps \u2014 verify <code>net.ipv4.tcp_timestamps=1<\/code> before trusting it.<\/li><li>Container network namespaces each have their own ephemeral range; a busy container can exhaust ports while the host looks idle.<\/li><\/ul>\n<!-- \/wp:list -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">SO_REUSEPORT: spreading accepts across workers<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A single listener means one accept path for every incoming connection. With any modern Linux and an evented server, <code>SO_REUSEPORT<\/code> lets each worker bind the same port and get its own accept queue, removing a contention point at high request rates. Nginx enables it per listen socket; check whether your build and config set it.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code>listen 443 ssl reuseport;\nlisten 80 reuseport;<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Verify the kernel accepted the reuse by inspecting the socket, or simply compare request throughput with and without it under sustained load. Do not enable it behind a proxy that relies on a single connection to reach all workers \u2014 pick one model or the other.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Watch the right counters<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:list -->\n<ul class=\"wp-block-list\"><li><code>nstat -az | grep -i -E \"listen|syn|overflow\"<\/code> shows dropped SYNs and listen overflows since boot.<\/li><li><code>ss -lnt<\/code> shows per-socket Recv-Q; a persistently non-zero value on a listener means the accept queue is backing up.<\/li><li>Track <code>net.ipv4.tcp_max_tw_buckets<\/code> versus actual TIME_WAIT count \u2014 if usage sits at the ceiling, TIME_WAIT sockets are being dropped and you have headroom to widen.<\/li><\/ul>\n<!-- \/wp:list -->\n\n<!-- wp:heading level=\"2\" -->\n<h2 class=\"wp-block-heading\">Set limits for the process, not just the kernel<\/h2>\n<!-- \/wp:heading -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">A high-connection process also needs its own file-descriptor limit raised, or it hits <code>EMFILE<\/code> long before the kernel runs out of ports. Check and raise the systemd unit limit for the service.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:code -->\n<pre class=\"wp-block-code\"><code># \/etc\/systemd\/system\/myapp.service.d\/limits.conf\n[Service]\nLimitNOFILE=65536<\/code><\/pre>\n<!-- \/wp:code -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">Then confirm the running process inherited it: <code>cat \/proc\/$(pidof myapp)\/limits | grep \"open files\"<\/code>. A widened port range with a low descriptor limit just moves the failure one layer up.<\/p>\n<!-- \/wp:paragraph -->\n\n<!-- wp:paragraph -->\n<p class=\"wp-block-paragraph\">These four settings \u2014 port range, backlog, tw_reuse, and reuseport \u2014 resolve the majority of connection failures that look like network problems. Test them under real load and watch the counters, not just the throughput number. For environment sizing, see the <a href=\"https:\/\/virtualserversvps.com\/cloud-vps-benefits\/\">cloud VPS benefits<\/a> overview, and browse <a href=\"https:\/\/virtualserversvps.com\/\">VPS tutorials<\/a> for related kernel tuning guides.<\/p>\n<!-- \/wp:paragraph -->","protected":false},"excerpt":{"rendered":"<p>When a busy server starts refusing new connections but traffic and CPU look normal, the cause is often a quiet resource limit: the ephemeral port range, or the loading of&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":4,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1210","post","type-post","status-publish","format-standard","hentry","category-performance-optimization"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.1 (Yoast SEO v26.1) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers - Virtual Servers VPS Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers\" \/>\n<meta property=\"og:description\" content=\"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers\" \/>\n<meta property=\"og:url\" content=\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/\" \/>\n<meta property=\"og:site_name\" content=\"Virtual Servers VPS Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-09-23T22:35:17+00:00\" \/>\n<meta name=\"author\" content=\"Virtual-Servers-Vps-Editor\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Virtual-Servers-Vps-Editor\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/\",\"name\":\"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers - Virtual Servers VPS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\"},\"datePublished\":\"2026-09-23T22:35:17+00:00\",\"author\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\"},\"breadcrumb\":{\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/virtualserversvps.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#website\",\"url\":\"https:\/\/virtualserversvps.com\/blog\/\",\"name\":\"Virtual Servers VPS Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0\",\"name\":\"Virtual-Servers-Vps-Editor\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g\",\"caption\":\"Virtual-Servers-Vps-Editor\"},\"sameAs\":[\"https:\/\/virtualserversvps.com\/blog\"],\"url\":\"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers - Virtual Servers VPS Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/","og_locale":"en_US","og_type":"article","og_title":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers","og_description":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers","og_url":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/","og_site_name":"Virtual Servers VPS Blog","article_published_time":"2026-09-23T22:35:17+00:00","author":"Virtual-Servers-Vps-Editor","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Virtual-Servers-Vps-Editor","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/","url":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/","name":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers - Virtual Servers VPS Blog","isPartOf":{"@id":"https:\/\/virtualserversvps.com\/blog\/#website"},"datePublished":"2026-09-23T22:35:17+00:00","author":{"@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0"},"breadcrumb":{"@id":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/virtualserversvps.com\/blog\/ephemeral-port-exhaustion-so-reuseport-tuning-linux-vps\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/virtualserversvps.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Ephemeral Port Exhaustion and SO_REUSEPORT Tuning on Linux Servers"}]},{"@type":"WebSite","@id":"https:\/\/virtualserversvps.com\/blog\/#website","url":"https:\/\/virtualserversvps.com\/blog\/","name":"Virtual Servers VPS Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/virtualserversvps.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/82a299a8284a66ff49f97c74684724a0","name":"Virtual-Servers-Vps-Editor","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/virtualserversvps.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d820b15f1cd028e97610d9adf536df7be5cb6423869967037d468d5355fa003f?s=96&d=mm&r=g","caption":"Virtual-Servers-Vps-Editor"},"sameAs":["https:\/\/virtualserversvps.com\/blog"],"url":"https:\/\/virtualserversvps.com\/blog\/author\/virtualserversvps\/"}]}},"_links":{"self":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/comments?post=1210"}],"version-history":[{"count":1,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1210\/revisions"}],"predecessor-version":[{"id":1211,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/posts\/1210\/revisions\/1211"}],"wp:attachment":[{"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/media?parent=1210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/categories?post=1210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/virtualserversvps.com\/blog\/wp-json\/wp\/v2\/tags?post=1210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}