Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

Linux: bind: Cannot assign requested address

EADDRNOTAVAIL means the kernel had no address to bind: too many TIME_WAIT sockets, an IP missing from the interface, or a wrong listen address.

~5 min readLinux
#linux#networking#sockets#troubleshooting
Bold white headline reading EADDRNOTAVAIL beside a cyan socket crate with an amber missing address plate.

Introduction & Quick Summary

A service that starts fine on a laptop refuses to start on a server, or an outbound connection fails under load:

code
Error: listen EADDRNOTAVAIL: address not available 192.168.1.10:8080 at Server.setupListenHandle (node:net:1908:16)
curl: (7) Failed to connect to 10.0.0.5 port 443: Cannot assign requested address

Quick answer: EADDRNOTAVAIL (errno 99, "Cannot assign requested address") means the kernel could not use the address it was asked to use. There are two very different situations behind the same message. When a server binds, the address must exist on one of its interfaces. When a client connects, the kernel must find a free local port for that connection, and under heavy churn it runs out.

bash
ip -brief addr # which addresses this host actually owns ss -ltnp | grep 8080 # what is listening, and on which address ss -s | grep -i time-wait # client-side port pressure sysctl net.ipv4.ip_local_port_range

The fix follows from which one it is: bind to an address the host has (often 0.0.0.0 or ::), or free up local ports with connection reuse and a wider ephemeral range. The rest of this guide separates the two cases, covers containers and IPv6, and shows the settings that keep a high-connection client from hitting the limit again.

Core Mechanics, Signatures & Reproducible Setup

A socket address is a pair: IP and port. bind() succeeds only if the IP is local to the current network namespace and the port is allowed; connect() picks a local IP and an ephemeral port automatically, and fails with the same errno when no combination is available.

bash
# reproduce the server-side case python3 -m http.server 8080 --bind 192.168.1.10 # OSError: [Errno 99] Cannot assign requested address # the same port on an address the host has python3 -m http.server 8080 --bind 127.0.0.1
c
// minimal bind that fails the same way int fd = socket(AF_INET, SOCK_STREAM, 0); struct sockaddr_in addr = {0}; addr.sin_family = AF_INET; addr.sin_port = htons(8080); inet_pton(AF_INET, "192.168.1.10", &addr.sin_addr); bind(fd, (struct sockaddr *)&addr, sizeof addr); // -1, errno 99

The client-side case needs no code, only churn: open thousands of short-lived connections to one destination, and once the ephemeral range is consumed by sockets in TIME_WAIT, new connects fail with errno 99 even though the network is fine.

bash
sysctl net.ipv4.ip_local_port_range # net.ipv4.ip_local_port_range = 32768 60999 (about 28k ports) cat /proc/net/sockstat # TCP: inuse 21455 orphan 0 tw 21903 alloc 22010 mem 64

tw is the count of sockets in TIME_WAIT. When it approaches the size of the ephemeral range, connection attempts start failing.

Key Comparison Table

SituationWhich call failsUsual causeFix
server startbind()IP not on the interfacebind 0.0.0.0, :: or the real IP
container startbind()manifest names a host IPbind inside the namespace
client under loadconnect()ephemeral ports exhaustedreuse connections, widen range
IPv6-only hostbind() to 127.0.0.1no IPv4 loopbackbind ::1 or enable IPv4
VPN or failoverbind()interface went downbind wildcard, not a VIP
after config changebind()address removedre-check ip addr
Language or toolMessage textErrno
Node.jslisten EADDRNOTAVAIL: address not available99
Javajava.net.BindException: Cannot assign requested address99
Gobind: cannot assign requested address99
PythonOSError: [Errno 99] Cannot assign requested address99
curlFailed to connect ... Cannot assign requested address99
Kernel settingDefaultEffect on this error
net.ipv4.ip_local_port_range32768 60999wider range means more client ports
net.ipv4.tcp_tw_reuse2 on modern kernelsallows reuse of TIME_WAIT for clients
net.ipv4.tcp_fin_timeout60shorter timeout frees ports faster
net.ipv4.tcp_max_tw_buckets262144caps TIME_WAIT sockets
net.ipv6.bindv6only0wildcard IPv6 also accepts IPv4

Practical Edge Cases, Error Fixes & Deep Dive Code Examples

1. Binding to an address that is not there

The message is literal: the host does not own that IP. Common causes are a hard-coded address from an old server, a Docker bridge IP written into a config file, a VPN address, or a keepalived VIP that has not moved to this node yet.

bash
ip -4 -brief addr show # lo 127.0.0.1/8 # eth0 10.0.4.17/24 grep -r "192.168.1.10" /etc/myapp/ # the stale value

Bind to 0.0.0.0 (all IPv4 interfaces) unless the service must be restricted to one interface, and pin the real interface in deployment config instead of the address. A VIP-based service should start before the VIP arrives only if it binds the wildcard address.

2. Containers and network namespaces

Inside a container, only the container's own addresses exist. A manifest that sets HOST=192.168.1.10 (the host's LAN address) fails at start with errno 99, while the same image works on the developer machine that has that address.

services: api: image: registry.example.com/api:1.3.0 environment: HOST: 0.0.0.0 # not the host's LAN IP ports: - "8080:8080"

With network_mode: host the container shares the host namespace, and then the host address does exist — which is why the same setting can behave differently between two compose files. Check from inside the container:

docker run --rm registry.example.com/api:1.3.0 ip -brief addr docker exec api ip -brief addr

3. IPv6, dual stack and localhost

A host with IPv6 disabled, or a container with ::1 only, fails when the application binds 127.0.0.1. The reverse also happens: an application that resolves localhost to ::1 and binds that, while clients connect to 127.0.0.1.

bash
cat /proc/sys/net/ipv6/conf/all/disable_ipv6 getent ahosts localhost ss -ltn | grep -E '::1|127.0.0.1'

Binding :: with the default bindv6only=0 accepts both families on Linux, which makes it the simplest default for a server that must serve both. Explicit 127.0.0.1 is fine only when every client also uses IPv4.

4. Client-side port exhaustion

This is the case that hides behind a healthy server. A batch job that opens a new TCP connection per request, with no keep-alive and a concurrency of a few thousand, will exhaust the ephemeral range within minutes; the failure looks random because the kernel only fails once the range is full.

bash
ss -tan state time-wait | wc -l cat /proc/sys/net/ipv4/ip_local_port_range ss -tan dst 10.0.0.5:443 | awk '{print $1}' | sort | uniq -c

Fixes, in order of effect: reuse connections (HTTP keep-alive or a connection pool), add Connection: close only where necessary, widen the ephemeral range, and reduce tcp_fin_timeout. For a client written in Go, an idle connection pool is the default with http.Transport; in Node.js, undici pools by origin — a new Agent per request defeats it.

js
// one dispatcher, reused for every request import { Agent, setGlobalDispatcher } from "undici" setGlobalDispatcher(new Agent({ connections: 64, keepAliveTimeout: 30_000 }))

5. Widen the range safely

bash
sysctl -w net.ipv4.ip_local_port_range="15000 65000" sysctl -w net.ipv4.tcp_tw_reuse=1

Persist it in /etc/sysctl.d/99-network.conf. A wider range increases the chance of a collision with services listening on low ports, so stop the range above the ports you actually use. tcp_tw_reuse applies to outbound connections only and is safe on current kernels; it does not help a server that cannot bind its listening port.

6. Confirm with the socket tables

ss and strace show which call failed and with what address, which avoids guessing between the two causes:

bash
strace -f -e trace=bind,connect ./server 2>&1 | grep -E 'bind|connect' # bind(3, {sa_family=AF_INET, sin_port=htons(8080), sin_addr=inet_addr("192.168.1.10")}, 16) = -1 EADDRNOTAVAIL ss -ltnp 'sport = :8080'

For checking whether the address a config file names belongs to the network at all, the CIDR calculator confirms the subnet and host range, and the curl command generator reproduces an outbound failure with the same source interface.

Common Compilation/Runtime Mistakes & Version Gotchas

  • Reading it as a port conflict. EADDRINUSE means the port is taken; EADDRNOTAVAIL means the address or local port pool is unusable. The fixes do not overlap.
  • Retrying the same connect in a tight loop. The port pool needs time or reuse to recover; the loop makes the TIME_WAIT count worse.
  • SO_REUSEADDR as a cure. It helps a server rebind after restart; it does nothing for an address the host does not own.
  • Hard-coded IPs in manifests and compose files. They work on one host and fail on the next; use the wildcard address and let the platform route.
  • Version notes. Recent kernels default tcp_tw_reuse to 2, which enables reuse for loopback and for connections with timestamps; older kernels default to 0, so a tuning guide written for years ago may describe a setting you no longer have to change.
  • Container hosts with net.ipv4.ip_local_port_range shared. In host networking the range is the host's; a single busy container can starve its neighbours, so per-container network namespaces are the better isolation.

Official documentation: ip(7) and tcp(7).

Official references

primary documentation

The Linux documentation that defines the behaviour this guide explains.

Try matching browser tools

All tools

Small utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.

All Linux guides

More in Linux

All Linux guides

The guides filed next to this one in Linux, in library order.