How to Fix Network 'No Route to Host' Errors on Linux
'No route to host' (Errno 113, EHOSTUNREACH) means a message came back saying the host can't be reached, or your own machine found nobody at that address. On four real Linux machines we find who said no each time: firewalld rejecting a port (and the rule lost on reload without --permanent), a moved address nobody answers, and a router reporting a PC that's off, plus how 'Network is unreachable' differs.
No route, but ping answers
Your app says: no route to host. Sarah has the same problem. She works at a freight yard, and her screen asks a server called tracker where the railcars are. It gets error one thirteen: no route to host. But ping, which sends two quick are-you-there messages, gets both answers back in a tenth of a millisecond. So is there a route or not? Three different machines can say no, and each one has a short fix. And one of them is a machine Sarah never even talked to.
python3 cars.pyTraceback (most recent call last): File "/usr/lib/python3.12/urllib/request.py", line 1344, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/usr/lib/python3.12/http/client.py", line 1365, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1411, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1360, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1120, in _send_output self.send(msg) File "/usr/lib/python3.12/http/client.py", line 1064, in send self.connect() File "/usr/lib/python3.12/http/client.py", line 1030, in connect self.sock = self._create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/socket.py", line 852, in create_connection raise exceptions[0] File "/usr/lib/python3.12/socket.py", line 837, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/sarah/cars.py", line 5, in <module> with urllib.request.urlopen("http://tracker:8080/cars", timeout=10) as r: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 215, in urlopen return opener.open(url, data, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 515, in open response = self._open(req, data) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 532, in _open result = self._call_chain(self.handle_open, protocol, protocol + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 492, in _call_chain result = func(*args) ^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 1373, in http_open return self.do_open(http.client.HTTPConnection, req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 1347, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 113] No route to host>
ping -c 2 trackerPING tracker (192.168.70.10) 56(84) bytes of data. 64 bytes from tracker (192.168.70.10): icmp_seq=1 ttl=64 time=0.119 ms 64 bytes from tracker (192.168.70.10): icmp_seq=2 ttl=64 time=0.246 ms --- tracker ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 1028ms rtt min/avg/max/mdev = 0.119/0.182/0.246/0.063 ms
Who says there's no route?
No route to host means some machine told your laptop it can't get there. It could be the host itself, a router on the way, or your own laptop, when it calls out and nobody answers. Let's catch which one is talking to Sarah.

A firewall that says unreachable
Sarah logs in to the tracker over ssh and runs tcpdump, which prints every message that arrives. From her laptop, netcat, a tool that only tries to connect, knocks on port eighty-eighty, the numbered door the tracker app listens behind. The request comes in, and the tracker itself answers: host unreachable, admin prohibited filter. A firewall, pretending the machine isn't there.
[sarah@tracker ~]$ sudo tcpdump -nni eth0 -c 2 'tcp port 8080 or icmp'dropped privs to tcpdump tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes 14:55:45.828238 IP 192.168.70.20.53110 > 192.168.70.10.8080: Flags [S], seq 2262581591, win 64240, options [mss 1460,sackOK,TS val 586240480 ecr 0,nop,wscale 10], length 0 14:55:45.828306 IP 192.168.70.10 > 192.168.70.20: ICMP host 192.168.70.10 unreachable - admin prohibited filter, length 68 2 packets captured 2 packets received by filter 0 packets dropped by kernel
nc -vz tracker 8080nc: connect to tracker (192.168.70.10) port 8080 (tcp) failed: No route to host
So, the usual fix: open the port. The tracker runs Rocky Linux, where the firewall, firewalld, is on from the start. Sarah lists what it lets in: a few services by name, like ssh, and no port numbers at all. She adds port eighty-eighty for TCP, the kind of connection most apps use. The firewall answers: success. The yard screen asks again: track three, twelve cars. For a well-known service, like ssh or http, dash dash add-service does the same by name.
[sarah@tracker ~]$ sudo firewall-cmd --list-allpublic target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client ssh ports: protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
[sarah@tracker ~]$ sudo firewall-cmd --add-port=8080/tcpsuccess
python3 cars.pytrack 3: 12 cars track 5: 8 cars track 7: 15 cars
But why did ping get through? firewalld groups its rules into zones, and the tracker's network card sits in the zone called public. That zone keeps a list of what may come in: a few services, and ping's are-you-there messages. Anything not on the list is turned away. Here it's turned away politely, with the message we caught earlier: admin prohibited. Your laptop shows that as no route to host. So ping proves the machine is there. It says nothing about port eighty-eighty.

Gone after a reload
That evening, Chris, who looks after the yard's servers, reloads the firewall after another change. Guess first: does the yard screen still work? No. Error one thirteen is back. The port Sarah added lived only in the firewall's running rules.
[sarah@tracker ~]$ sudo firewall-cmd --reloadsuccess
python3 cars.pyTraceback (most recent call last): File "/usr/lib/python3.12/urllib/request.py", line 1344, in do_open h.request(req.get_method(), req.selector, req.data, headers, File "/usr/lib/python3.12/http/client.py", line 1365, in request self._send_request(method, url, body, headers, encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1411, in _send_request self.endheaders(body, encode_chunked=encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1360, in endheaders self._send_output(message_body, encode_chunked=encode_chunked) File "/usr/lib/python3.12/http/client.py", line 1120, in _send_output self.send(msg) File "/usr/lib/python3.12/http/client.py", line 1064, in send self.connect() File "/usr/lib/python3.12/http/client.py", line 1030, in connect self.sock = self._create_connection( ^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/socket.py", line 852, in create_connection raise exceptions[0] File "/usr/lib/python3.12/socket.py", line 837, in create_connection sock.connect(sa) OSError: [Errno 113] No route to host During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/sarah/cars.py", line 5, in <module> with urllib.request.urlopen("http://tracker:8080/cars", timeout=10) as r: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 215, in urlopen return opener.open(url, data, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 515, in open response = self._open(req, data) ^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 532, in _open result = self._call_chain(self.handle_open, protocol, protocol + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 492, in _call_chain result = func(*args) ^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 1373, in http_open return self.do_open(http.client.HTTPConnection, req) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/urllib/request.py", line 1347, in do_open raise URLError(err) urllib.error.URLError: <urlopen error [Errno 113] No route to host>
firewalld's own documentation explains it. The runtime configuration is what's in effect right now, and a reload replaces it with the permanent one. So a rule added without dash dash permanent is gone after a reload, or a reboot.

So Sarah adds it with dash dash permanent. That only writes the saved rules, so she reloads to make them live. list-ports shows eighty-eighty, and the yard screen works, now and after the next reboot. If you've already opened ports the quick way, dash dash runtime-to-permanent saves everything that's running now.
[sarah@tracker ~]$ sudo firewall-cmd --permanent --add-port=8080/tcpsuccess
[sarah@tracker ~]$ sudo firewall-cmd --reloadsuccess
[sarah@tracker ~]$ sudo firewall-cmd --list-ports8080/tcp
python3 cars.pytrack 3: 12 cars track 5: 8 cars track 7: 15 cars
Those saved rules live in the public zone's file, under slash etc slash firewalld. It gets one new line: port eighty-eighty, TCP. The firewall reads that file every time it starts.

Nobody at that address
Monday morning: the same error, but slower. Over the weekend, Chris moved the tracker from its old address, ending in dot ten, to a new one ending in dot eleven. netcat waits three seconds before it says no route to host. Inside one network, your laptop can't just send to an address. It first has to find the network card that owns it. So it shouts: who has dot ten? That shout is called ARP. ip neigh shows the answer it got: none. Failed.
time nc -vz -w 10 tracker 8080nc: connect to tracker (192.168.70.10) port 8080 (tcp) failed: No route to host real 0m3.050s user 0m0.000s sys 0m0.001s
ip neigh show 192.168.70.10192.168.70.10 dev eth0 FAILED
It's like a courier knocking at number ten on your own street. Nobody opens, so after a few knocks the parcel comes back marked: can't deliver. Nobody refused it. There's simply nobody at that door.

Ping now says: destination host unreachable. Guess first: which machine sent that? Sarah's own laptop, the one that shouted for dot ten and got no answer. getent, which looks up a name the same way apps do, shows why it asked for dot ten: the laptop's hosts file, its own little address book, still maps the name tracker there. sed, a find-and-replace tool, swaps in dot eleven, and the screen works.
ping -c 3 trackerPING tracker (192.168.70.10) 56(84) bytes of data. From yard-office (192.168.70.20) icmp_seq=1 Destination Host Unreachable From yard-office (192.168.70.20) icmp_seq=2 Destination Host Unreachable From yard-office (192.168.70.20) icmp_seq=3 Destination Host Unreachable --- tracker ping statistics --- 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2040ms pipe 3
getent hosts tracker192.168.70.10 tracker
sudo sed -i 's/^192.168.70.10/192.168.70.11/' /etc/hosts
python3 cars.pytrack 3: 12 cars track 5: 8 cars track 7: 15 cars
A machine behind the router
Here's the no from a machine Sarah never talked to. The scale house PC sits on another network, and the yard's router passes Sarah's traffic across to it. First, curl, a tool that fetches web pages, asks the PC for its page, and it answers with the last weight. Then the PC is switched off for the night, and netcat waits three seconds: no route to host. Ping says who: the yard router. It knocked on the PC's door for Sarah, got no answer, and sent the message back.
curl -s http://scale/Last weight: car 4417, 61.2 tonnes
time nc -vz -w 10 scale 80nc: connect to scale (10.20.0.5) port 80 (tcp) failed: No route to host real 0m3.098s user 0m0.001s sys 0m0.000s
ping -c 3 scalePING scale (10.20.0.5) 56(84) bytes of data. From yard-router (192.168.70.1) icmp_seq=1 Destination Host Unreachable From yard-router (192.168.70.1) icmp_seq=2 Destination Host Unreachable From yard-router (192.168.70.1) icmp_seq=3 Destination Host Unreachable --- scale ping statistics --- 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2041ms pipe 3
Not the same: network unreachable
Sometimes the error looks almost the same, network is unreachable, and every fix so far will fail on it. Every machine needs a gateway: the router it hands traffic to when the address is on another network. Say Sarah's laptop gets its address typed in by hand, and nobody sets the gateway. netcat fails at once. ip route lists only one road: the office network. Then ip route get asks: which road would you take to the scale house PC? There's no answer at all. The fix is to give her laptop its gateway back: a default route via the yard router. With that in place, the weight comes back.
nc -vz scale 80nc: connect to scale (10.20.0.5) port 80 (tcp) failed: Network is unreachable
ip route192.168.70.0/24 dev eth0 proto kernel scope link src 192.168.70.20
ip route get 10.20.0.5RTNETLINK answers: Network is unreachable
sudo ip route add default via 192.168.70.1
ip route get 10.20.0.510.20.0.5 via 192.168.70.1 dev eth0 src 192.168.70.20 uid 1000 cache
curl -s http://scale/Last weight: car 4417, 61.2 tonnes
So: no route to host means your machine knew where to send it, and something along the way said the host can't be reached. Network is unreachable means your own machine doesn't know where to send it at all.

Before you call it fixed
Before you call it fixed, reload the firewall or reboot, then test again. Test from another machine, because the firewall only checks traffic from outside. And if the error comes back, ask who said no.

Recap
So, no route to host: a firewall answering for the host, an address nobody has, or a router reporting a machine that's off. And when it comes back, ping tells you who said no.

If your yard screen finds its tracker again, a like helps the next stuck beginner find this, and subscribing brings more fixes, tested on real machines.
Every error in this video came from four real Linux machines, and every command and the lab files are linked in the description. Thanks for watching Cloud Explainers.
Sources
- connect(2): EHOSTUNREACH and ENETUNREACH
- firewalld, Runtime versus Permanent (a reload replaces the runtime configuration with the permanent one)
- firewall-cmd(1): --add-port, --permanent, --reload, --list-all, --list-ports
- firewalld.zone(5): a zone's default target rejects other traffic with an ICMP host prohibited message
- RFC 1122, Requirements for Internet Hosts (a router that can't deliver a packet sends ICMP destination unreachable)
- ip-neighbour(8): FAILED, the neighbour did not answer
- ip-route(8): ip route, ip route get, default via
Demos: four containers on our own Mac standing in for a freight yard's laptop, tracker server, router and scale house PC; the yard and its staff are made up. Every error and packet was real. Watch the full video on YouTube.