How to Fix EHOSTUNREACH (No Route to Host)
Learn whether the host is off, your route is blocked or a firewall rejects you, then fix that part.
Updated
TL;DR
EHOSTUNREACH means your operating system, or a router or firewall on the way, reported that the IP in the message cannot be reached, so no server program ever saw your request. Check first that the host is on and still uses that address.
What EHOSTUNREACH looks like in each client
Your own IP and port replace the examples. If connect() fails at once, Node.js appends - Local (...). curl's last line says only Couldn't connect to server; -v shows the cause.
| Where | What you see |
|---|---|
| Node.js http, https and net | Error: connect EHOSTUNREACH 192.168.1.20:8080 |
| Node.js fetch() and its cause | TypeError: fetch failed ... [cause]: Error: connect EHOSTUNREACH 192.168.1.20:8080 |
| Python requests on Linux | Failed to establish a new connection: [Errno 113] No route to host |
| Python on macOS (socket, urllib) | OSError: [Errno 65] No route to host |
| curl -v on Linux (exit code 7) | * connect to 192.168.1.20 port 8080 from 192.168.1.5 port 52144 failed: No route to host |
| OpenSSH | ssh: connect to host 192.168.1.20 port 22: No route to host |
| Chrome, direct connection | This site can't be reached http://192.168.1.20:8080/ is unreachable. ERR_ADDRESS_UNREACHABLE |
Why this happens
No working path led from your computer to that IP address.
On Linux, a host that is switched off or now has another IP causes it: nothing on your local network answers the ARP request for that address, so after about 3 seconds the system gives up.
Diagnose your EHOSTUNREACH first
Five checks, starting with one you can do from your phone.
Open the address on another device on that network, such as your phone; if that fails too, the cause is the host, not your computer.
Compare the IP in the message with your proxy's; if they match, the missing route leads to the proxy, not the site.
Run ip route get with that IP on Linux, or route -n get on macOS; a VPN interface listed there means the tunnel carries it.
On Linux, ping the host; if it answers while the port still fails, a firewall on the way rejects that port.
On macOS 15 or later, run the script in the Terminal app; if it connects only there, your editor lacks Local Network access.
Solutions ranked by effectiveness
Host first, then your own machine's route, then the firewall.
- Most common fix
Bring the host back at its current address
Applies when nothing on the network gets an answer from it. Power it on, then confirm its IP, because routers lease addresses for a limited time and may hand out a new one.
Check that the host is powered on and joined to your network.
Read its current IP on the host itself, for example with ip addr on Linux.
Put that IP in your code, config file or proxy settings, then retry.
- Check next
Give your app a route to the host
Applies when only your machine fails. On a Mac, check Local Network access; on any system, check the VPN.
On macOS 15 or later, open System Settings > Privacy & Security > Local Network.
Turn on the app that starts your code, such as your editor, and retry.
Disconnect the VPN and retry; if it then works, have its admin exclude that subnet.
- Site owners
Open the port in the host's firewall
Applies when the server runs firewalld and nobody opened the port in its zone. Open only the port your clients need.
Find the zone of the server's interface with firewall-cmd --get-active-zones, often public.
Run sudo firewall-cmd --zone=public --permanent --add-port=8080/tcp && sudo firewall-cmd --reload.
Connect again from the client to confirm the port now opens.
Stop the EHOSTUNREACH from coming back
Habits that keep addresses fixed and routes predictable after restarts and VPN changes.
Reserve the host's IP in your router's DHCP settings, so the address stays the same after every restart.
On macOS, start scripts that talk to local devices from Terminal or as a launchd daemon, which macOS allows automatically.
Log err.code and err.address for every failed connection, so the log shows which hop had no route.
After editing firewalld rules, run firewall-cmd --list-ports to spot a missing port before clients do.
Related errors
Learn more
FAQ
Proxy lists built to your settings
Geonode's Endpoint Generator lists ready endpoints to copy, or to download as a .txt file.


