Executing an SSH connection, pinging a remote server, or establishing a database handshake in the Linux command line only to be stopped by the error message: “connect to host x.x.x.x port 22: No route to host”, “ssh: connect to host: No route to host”, or programmatic code EHOSTUNREACH (errno 113) halts network workflows immediately. In the Linux TCP/IP networking stack, EHOSTUNREACH indicates that an intermediate router, local packet filter, or the local kernel routing table cannot find a valid path to deliver packets to the target IP address. Unlike a connection timeout (where packets are sent into a void) or connection refused (where the target host actively rejects the port), “No route to host” means a network device explicitly returned an ICMP Type 3 (Destination Unreachable) packet back to your client. This guide provides a complete diagnostic workflow to troubleshoot and fix this network failure.
What Causes ‘No Route to Host’ in Linux?
Several transport and network layer components generate host unreachable responses:
- Target Server Firewall Reject Rules: The destination server’s firewall (such as
iptables,firewalld, orufw) is configured to actively reject packets with an ICMP unreachable message (--reject-with icmp-host-unreachableoricmp-port-unreachable) rather than dropping them. - Local or Gateway Routing Table Inconsistencies: A missing, corrupted, or misconfigured default gateway in the local routing table (
ip route) directing traffic into the wrong interface. - Subnet and Netmask Mismatches: The client host and destination host are assigned conflicting subnet masks (e.g.,
/24vs/16) causing the kernel to mistake a local device for an external network. - IP Address Collisions on the Local Subnet: Two machines sharing the same static IP address causing ARP cache confusion across local network switches.
- Docker and VPN Routing Overlaps: Virtual network bridges (such as Docker’s
172.17.0.0/16or WireGuard/OpenVPN interfaces) overlapping with your destination enterprise IP ranges.
Method 1: Trace the Network Path with traceroute and mtr
To determine exactly which hop or router is generating the ICMP unreachable packet, trace the packet path across network hops.
- Run a modern path trace using traceroute or mtr:
(Usingtraceroute -n -T -p 22 192.168.1.150-Tsends TCP SYN packets to port 22, mimicking SSH rather than UDP). - Analyze the final responsive hop:
- If the trace terminates at your local default gateway (e.g.,
192.168.1.1), the router cannot locate the destination IP on the WAN/LAN. - If the trace reaches the destination server’s IP address and immediately outputs
!H(Host Unreachable) or!X(Administratively Prohibited), the target server’s own firewall is rejecting the connection.
- If the trace terminates at your local default gateway (e.g.,
Method 2: Inspect and Flush Firewall Reject Rules on the Target Host
In the vast majority of Linux server environments, “No route to host” on standard ports (22, 80, 443) is caused by active firewall rejection rules on the target machine.
For firewalld (RHEL, AlmaLinux, Rocky Linux, CentOS):
- Log in to the destination server (via console or alternative management IP).
- Inspect active zone rules:
sudo firewall-cmd --list-all - If the service or port is missing from the active zone, add it:
sudo firewall-cmd --permanent --add-service=ssh sudo firewall-cmd --permanent --add-port=22/tcp sudo firewall-cmd --reload
For iptables:
- Check for explicit
REJECTrules in theINPUTchain:sudo iptables -L INPUT -v -n --line-numbers - Look for rules with target
REJECTand reject-withicmp-host-unreachable. - Insert an allow rule before the reject rule:
sudo iptables -I INPUT 1 -p tcp --dport 22 -j ACCEPT
Method 3: Check and Reconfigure the Linux Routing Table
If your Linux machine has multiple network interfaces (e.g., Wi-Fi, Ethernet, and VPN), traffic destined for your target host may be routing through the wrong interface.
- Check which route your system selects to reach the destination:
ip route get 192.168.1.150 - Inspect the output: verify that the selected
dev(interface) andvia(gateway IP) correspond to your actual physical network card. - If the output returns
RTNETLINK answers: Network is unreachable, add a valid default route:sudo ip route add default via 192.168.1.1 dev eth0 - If an incorrect static route exists, delete it:
sudo ip route del 192.168.1.0/24 dev wlan0
Method 4: Flush and Verify the Local ARP Cache
Stale or poisoned ARP (Address Resolution Protocol) cache entries cause your network card to transmit packets to the wrong physical MAC address.
- Inspect the current ARP table for the destination IP:
ip neigh show 192.168.1.150 - If the entry displays
FAILEDorINCOMPLETE, your machine cannot resolve the MAC address on the local physical segment. - Flush the neighbor entry to force a fresh ARP broadcast:
sudo ip neigh flush dev eth0 - Ping the target host again to verify if fresh ARP resolution succeeds.
Method 5: Resolve Docker Bridge and VPN Subnet Conflicts
Default Docker bridge networks frequently utilize the 172.17.0.0/16 subnet, which conflicts with corporate intranets.
- Inspect active virtual bridge interfaces:
ip addr show docker0 - If the Docker bridge subnet overlaps with your remote server IP range, reconfigure the Docker daemon default address pool in
/etc/docker/daemon.json:{ "default-address-pools": [ { "base": "10.200.0.0/16", "size": 24 } ] } - Restart Docker:
sudo systemctl restart docker
EHOSTUNREACH Diagnostic Checkpoints
| Layer | Diagnostic Tool | Resolution Action |
|---|---|---|
| Firewall (Host) | iptables -L / firewall-cmd | Open TCP port and remove ICMP reject rule |
| Routing (Kernel) | ip route get [IP] | Configure valid default gateway on correct interface |
| Data Link (L2) | ip neigh show | Flush stale ARP cache with ip neigh flush |
| Virtualization | ip addr show docker0 | Change Docker default-address-pools subnet |
Following this structured diagnostic methodology ensures you quickly isolate whether an ICMP reject rule, an ARP failure, or a routing table overlap is causing the unreachable host error.