Home › SSH

ssh: connect to host port 22: No route to host — how to fix

ssh: connect to host 192.168.1.50 port 22: No route to host

Quick fix: Check the host is up and the IP is right: ping 192.168.1.50, ip route get 192.168.1.50. If it pings but SSH says no route, the target's firewall is rejecting port 22: allow it with sudo firewall-cmd --permanent --add-service=ssh && sudo firewall-cmd --reload (RHEL/Fedora) or sudo ufw allow ssh (Ubuntu). Also check VPN, wrong subnet and whether the VM/container network is bridged.

What it means

No route to host is EHOSTUNREACH. Compare with similar SSH errors:

Error Meaning
Connection refused Host reached, nothing listening on 22
Connection timed out Packets silently dropped
No route to host Host unreachable, or a firewall rejected with ICMP host-unreachable / host-prohibited

So two very different situations produce it: the host really isn't there, or it is there and its firewall says no.

Step 1: is the host reachable at all?

ping -c 3 192.168.1.50
ip route get 192.168.1.50     # which interface/gateway would be used
ip neigh | grep 192.168.1.50  # on the same LAN: FAILED/INCOMPLETE = no ARP reply

Step 2: host pings, but SSH says no route - firewall

RHEL, CentOS, Fedora and Rocky's firewalld (and iptables rules ending in REJECT --reject-with icmp-host-prohibited) return this error for blocked ports. On the target:

sudo firewall-cmd --list-all
sudo firewall-cmd --permanent --add-service=ssh    # or --add-port=2222/tcp
sudo firewall-cmd --reload

Ubuntu/Debian with ufw:

sudo ufw status
sudo ufw allow OpenSSH

Raw iptables: sudo iptables -L INPUT -n --line-numbers and look for a REJECT before an ACCEPT for port 22.

Also make sure sshd is actually running and listening: sudo ss -ltnp | grep sshd.

Step 3: virtual machines and containers

Step 4: cloud servers

In AWS, GCP and Azure a missing security group/firewall rule normally causes a timeout, but a wrong subnet route table, a stopped instance, or an IP that changed after stop/start can give No route to host. Check the instance state and current public IP, and that port 22 is allowed from your IP.

Debug output

ssh -v user@192.168.1.50
nc -vz 192.168.1.50 22

If nc also fails with no route, the problem is the network or firewall, not SSH keys or config.

Last updated 2026-11-24.