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.

Introduction & Quick Summary
A service that starts fine on a laptop refuses to start on a server, or an outbound connection fails under load:
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.
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_rangeThe 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.
# 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// 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 99The 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.
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 64tw is the count of sockets in TIME_WAIT. When it approaches the size of the ephemeral range, connection attempts start failing.
Key Comparison Table
| Situation | Which call fails | Usual cause | Fix |
|---|---|---|---|
| server start | bind() | IP not on the interface | bind 0.0.0.0, :: or the real IP |
| container start | bind() | manifest names a host IP | bind inside the namespace |
| client under load | connect() | ephemeral ports exhausted | reuse connections, widen range |
| IPv6-only host | bind() to 127.0.0.1 | no IPv4 loopback | bind ::1 or enable IPv4 |
| VPN or failover | bind() | interface went down | bind wildcard, not a VIP |
| after config change | bind() | address removed | re-check ip addr |
| Language or tool | Message text | Errno |
|---|---|---|
| Node.js | listen EADDRNOTAVAIL: address not available | 99 |
| Java | java.net.BindException: Cannot assign requested address | 99 |
| Go | bind: cannot assign requested address | 99 |
| Python | OSError: [Errno 99] Cannot assign requested address | 99 |
| curl | Failed to connect ... Cannot assign requested address | 99 |
| Kernel setting | Default | Effect on this error |
|---|---|---|
net.ipv4.ip_local_port_range | 32768 60999 | wider range means more client ports |
net.ipv4.tcp_tw_reuse | 2 on modern kernels | allows reuse of TIME_WAIT for clients |
net.ipv4.tcp_fin_timeout | 60 | shorter timeout frees ports faster |
net.ipv4.tcp_max_tw_buckets | 262144 | caps TIME_WAIT sockets |
net.ipv6.bindv6only | 0 | wildcard 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.
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 valueBind 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 addr3. 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.
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.
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 -cFixes, 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.
// one dispatcher, reused for every request
import { Agent, setGlobalDispatcher } from "undici"
setGlobalDispatcher(new Agent({ connections: 64, keepAliveTimeout: 30_000 }))5. Widen the range safely
sysctl -w net.ipv4.ip_local_port_range="15000 65000"
sysctl -w net.ipv4.tcp_tw_reuse=1Persist 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:
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.
EADDRINUSEmeans the port is taken;EADDRNOTAVAILmeans 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_WAITcount worse. SO_REUSEADDRas 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_reuseto2, which enables reuse for loopback and for connections with timestamps; older kernels default to0, 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_rangeshared. 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 references
primary documentationThe Linux documentation that defines the behaviour this guide explains.
Try matching browser tools
All toolsSmall utilities that fit Linux work — they run entirely in this browser tab, so nothing you paste leaves your device.
Related Linux guides
All Linux guidesnginx 502 Bad Gateway: upstream connection refused
The log line names the address and errno, which is the diagnosis. Fix the host, the start-up order, the buffers, or the timeout that actually fired.
Linux: Read-only file system (EROFS) on a mounted volume
EROFS is a mount condition, not a permission error. Read the kernel log first: I/O errors, a full thin pool, an ro fstab entry or a read-only root.
Linux Networking Diagnostics: ss, ip, dig, curl, and TCP Troubleshooting
A layer-by-layer path from interface to TLS that localises a failure in five commands, with the socket states and curl timings that identify each cause.
apt: The repository does not have a Release file
apt disables any repository whose Release file returns 404. Correct the suite name, move an end-of-life release to the archive host, or remove a dead repo.
More in Linux
All Linux guidesThe guides filed next to this one in Linux, in library order.