How to fix "ssh: connect to host port 22: No route to host"

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with OpenSSH 9.6p1 and iptables, November 29, 2026.

No route to host means something on the network answered that the server can’t be reached. Either a firewall is rejecting your connection with an “unreachable” reply, the machine at that address is off or gone, or your computer has no network path to that address (a different subnet, a VPN that isn’t connected). Unlike a timeout, you got a quick, definite no.

We reproduced it with OpenSSH 9.6 by adding a firewall rule that rejects port 2340 with an ICMP host-unreachable reply, while a server was listening there:

ssh: connect to host 127.0.0.3 port 2340: No route to host

The server was running the whole time; the firewall rule alone caused the message.

Find your cause

Situation What to check
A server firewall rejects port 22 On the server: sudo iptables -L -n or sudo firewall-cmd --list-all for a REJECT rule on port 22 (icmp-host-unreachable or icmp-host-prohibited both show up as this error)
The machine is off or its IP changed Look up its current address on the device, your router or the cloud console
Different network or subnet Your IP and the server’s should share a network, or there must be a route (VPN, gateway) between them
VPN not connected Internal addresses like 10.x.x.x often only work on the company VPN
A VM using NAT The VM’s address is private to the host; use port forwarding or bridged networking

Fix: allow SSH through the server’s firewall

On Fedora, RHEL, CentOS and Rocky Linux, firewalld rejects connections it blocks rather than dropping them silently, so a closed port tends to show up as No route to host. Allow SSH:

sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload

On Ubuntu and Debian with ufw: sudo ufw allow OpenSSH. We tested the reject rule with iptables; the firewalld and ufw commands are those tools’ standard ones and we didn’t run them here.

Fix: find the machine’s current address

On the machine itself, ip addr (Linux) or ipconfig (Windows) shows its address. If it changes after each restart, give it a fixed address in your router’s DHCP settings, or connect by name if your network supports it (for example raspberrypi.local).

Confirm it worked

nc -zv server 22 reports the port open and ssh -v reaches Connection established. If the error changes to Connection timed out or Connection refused, you’ve moved one step along; see Connection timed out or Connection refused.

FAQ

Is No route to host a problem with my SSH key?

No. The connection never reached the SSH server, so keys and passwords weren't involved yet. Fix the network path first.

Why can I ping the server but not SSH to it?

Ping uses ICMP and SSH uses TCP port 22, so a firewall can allow one and reject the other. A firewall rule that rejects port 22 with a host-unreachable reply produces exactly this error even though ping works.

Why does it happen with a Raspberry Pi or a VM on my network?

Usually the device's IP address changed (DHCP gave it a new one), it's on another network or subnet, or a VM uses NAT so it isn't directly reachable. Check its current IP on the device or your router.