ENETUNREACH
Linux / POSIXERRORNotableNetworkHIGH confidence
Network Is Unreachable
Production Risk
Check routing table and gateway configuration; common in misconfigured containers.
What this means
ENETUNREACH (errno 101) is returned when a connect() or send() fails because no route exists to the destination network. Unlike EHOSTUNREACH, this refers to the entire network being unreachable, not just a single host.
Why it happens
- 1No route to the destination network in the routing table
- 2Default gateway not configured
- 3Destination network behind a VPN that is disconnected
How to reproduce
connect() to an IP with no route in the routing table.
trigger — this will error
trigger — this will error
// Destination network 10.5.0.0/16 has no route connect(sockfd, (struct sockaddr*)&addr, sizeof(addr)); // Returns -1, errno = ENETUNREACH
expected output
connect: Network is unreachable (ENETUNREACH)
Fix
Add a route or configure the default gateway
WHEN When ENETUNREACH is returned
Add a route or configure the default gateway
# Check routing table ip route show # Add a default gateway ip route add default via 192.168.1.1 # Add a specific route ip route add 10.5.0.0/16 via 10.0.0.1 dev eth0
Why this works
ENETUNREACH means no routing entry; add the missing route or default gateway.
Sources
Official documentation ↗
Linux Programmer Manual ip(7)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev