<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Eaddrnotavail on K-Life Hack | Systems Architecture &amp; DevOps</title><link>https://klifehack.com/en/tags/eaddrnotavail/</link><description>Recent content in Eaddrnotavail on K-Life Hack | Systems Architecture &amp; DevOps</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Thu, 23 Jul 2026 10:11:53 +0900</lastBuildDate><atom:link href="https://klifehack.com/en/tags/eaddrnotavail/index.xml" rel="self" type="application/rss+xml"/><item><title>Analysis of EADDRNOTAVAIL Error and TIME_WAIT Optimization in Linux</title><link>https://klifehack.com/en/p/linux-tcp-time-wait-eaddrnotavail-optimization/</link><pubDate>Thu, 23 Jul 2026 10:11:53 +0900</pubDate><guid>https://klifehack.com/en/p/linux-tcp-time-wait-eaddrnotavail-optimization/</guid><description>&lt;h1 id="analysis-of-eaddrnotavail-error-and-kernel-parameter-optimization"&gt;Analysis of EADDRNOTAVAIL Error and Kernel Parameter Optimization
&lt;/h1&gt;&lt;p&gt;In systems with microservice architectures or high-frequency API calls, &lt;b&gt;EADDRNOTAVAIL&lt;/b&gt; (Cannot assign requested address) errors may occur when attempting to connect to external resources. This is a typical infrastructure bottleneck caused by the exhaustion of network resources at the OS level, specifically source ports. Ad-hoc manual workarounds increase management costs as the number of nodes grows, ultimately compromising overall system availability.&lt;/p&gt;
&lt;h2 id="eaddrnotavail-occurrence-mechanism"&gt;EADDRNOTAVAIL Occurrence Mechanism
&lt;/h2&gt;&lt;p&gt;When an application initiates a new TCP connection, the Linux kernel assigns a &lt;b&gt;4-tuple&lt;/b&gt; (source IP, source port, destination IP, destination port) to identify the connection. The EADDRNOTAVAIL error occurs when the kernel cannot secure the source port required to complete this combination. This is a clear signal that the networking stack is in a resource-exhausted state or that a configuration mismatch has occurred.&lt;/p&gt;
&lt;h2 id="primary-causes-in-production-environments"&gt;Primary Causes in Production Environments
&lt;/h2&gt;&lt;p&gt;In practical troubleshooting, the following factors are frequently identified: ephemeral port exhaustion, port occupation by a large number of &lt;b&gt;TIME_WAIT&lt;/b&gt; sockets, invalid bind attempts to IP addresses not assigned to network interfaces, conflicts in Docker or Kubernetes network namespaces, and file descriptor (FD) leaks due to improper socket closure on the application side.&lt;/p&gt;
&lt;h2 id="diagnostic-protocols-and-verification-commands"&gt;Diagnostic Protocols and Verification Commands
&lt;/h2&gt;&lt;p&gt;When a failure occurs, a process to sample the kernel state and identify the bottleneck is required. 🛠️&lt;/p&gt;
&lt;h3 id="1-checking-the-ephemeral-port-range"&gt;1. Checking the Ephemeral Port Range
&lt;/h3&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;cat /proc/sys/net/ipv4/ip_local_port_range
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If the default value (e.g., 32768 60999) is too narrow, it physically limits the number of concurrent connections.&lt;/p&gt;
&lt;h3 id="2-quantifying-the-time_wait-state"&gt;2. Quantifying the TIME_WAIT State
&lt;/h3&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ss -ant | grep TIME-WAIT | wc -l
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If this number is in the tens of thousands, intervention is required to improve port reuse efficiency.&lt;/p&gt;
&lt;h3 id="3-checking-socket-statistics-summary"&gt;3. Checking Socket Statistics Summary
&lt;/h3&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;ss -s
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Analyze the ratio of ESTABLISHED to TIME_WAIT and strengthen monitoring for any abnormal upward trends.&lt;/p&gt;
&lt;h2 id="implementing-kernel-parameter-optimization"&gt;Implementing Kernel Parameter Optimization
&lt;/h2&gt;&lt;p&gt;Based on the identified bottlenecks, edit &lt;code&gt;/etc/sysctl.conf&lt;/code&gt; to adjust the parameters. These settings improve port reusability under high-load environments and optimize resource turnover. ⚠️&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Expand the ephemeral port range&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;net.ipv4.ip_local_port_range &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1024&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;65535&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Allow reuse of sockets in TIME_WAIT state for new connections&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;net.ipv4.tcp_tw_reuse &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;1&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Reduce the retention time for FIN-WAIT-2 state (from default 60s to 30s)&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;net.ipv4.tcp_fin_timeout &lt;span style="color:#f92672"&gt;=&lt;/span&gt; &lt;span style="color:#ae81ff"&gt;30&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Apply settings&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;sysctl -p
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="troubleshooting-practical-considerations"&gt;Troubleshooting: Practical Considerations
&lt;/h2&gt;&lt;p&gt;Simply expanding the port range may not lead to a fundamental resolution. Regarding the application of &lt;b&gt;tcp_tw_reuse&lt;/b&gt;, rigorous validation in a staging environment is mandatory due to the risk of packet drops caused by timestamp mismatches under specific NAT topologies. Additionally, instead of generating a large number of short-lived connections, application-side modifications should be considered to suppress socket creation and destruction costs by utilizing Keep-Alive or Connection Pooling. Furthermore, ensure that the interface is in the &lt;b&gt;UP&lt;/b&gt; state to rule out defects at the physical layer.&lt;/p&gt;
&lt;h2 id="example-of-operational-verification-logs"&gt;Example of Operational Verification Logs
&lt;/h2&gt;&lt;p&gt;After applying the configuration changes, execute a verification process to make a final check on system integrity and parameter application status.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-text" data-lang="text"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Verify the applied port range
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ sysctl net.ipv4.ip_local_port_range
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;net.ipv4.ip_local_port_range = 1024 65535
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Monitor socket usage in real-time
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ss -s
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;Total: 1250 (kernel 1300)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;TCP: 850 (estab 400, closed 300, orphaned 0, timewait 150)
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;# Check file descriptors for a specific process
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;$ ls /proc/$(pgrep nginx | head -n 1)/fd | wc -l
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;128
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="operational-notes"&gt;Operational Notes
&lt;/h2&gt;&lt;p&gt;EADDRNOTAVAIL is a critical warning that the Linux kernel has rejected a request for network resources. Resolution requires a multi-faceted approach combining the expansion of the ephemeral port range, analysis of TIME_WAIT behavior, and optimization of socket management at the application layer. Especially in containerized environments, paying attention to discrepancies in limit values between the host and container network namespaces to maintain overall infrastructure consistency directly impacts operational stability.&lt;/p&gt;</description></item></channel></rss>