How to Fix “No Route to Host” Connection Error in Linux

When you’re trying to connect to a service on Linux, “No route to host” is one of the last things that you want to hear. It’s a broad message that means that your computer can’t reach the target server.

Because of the broad nature of the message there are several possibilities that could be causing it.

Host Is Offline/Service Isn’t Running

It might seem painfully obvious, but you should first check that the server that you’re trying to connect to is even online. It might have been taken down for maintenance or be experiencing issues.

Service stopped

The service itself might not have been started. If it’s your server, you can check to see if the service has been started and is running properly. To do that with Systemd, run the following command.

Wrong Port

You may be trying to connect on the incorrect port. Many system administrators choose to run commonly targeted services like SSH on different ports to help thwart would-be attackers.

If the server isn’t your own, check the available documentation or contact their support services.

Service On Different Port

For your own server, you can try using NMAP to figure out where you started your service.

If you think you used a really obscure port, you can use the -p- flag to scan them all. It will take a while though.

Iptables Is Blocking the Connection

You may have accidentally configured iptables to block connections on that port. You would receive the same message whether you configured iptables on the server or your desktop, so it’s worth checking both. To see your iptables rules, run the following command.

Your DNS Is Improperly Configured

If all else fails, you should try to ping the IP address that you’re looking to connect to. It could be that your computer isn’t connecting to a DNS server properly.

If the ping works but connecting a domain name doesn’t, you’re looking at a DNS issue.

Systemd users can run systemd-resolve --status to check the DNS servers that your system is using. It’s broken down by interface, so make sure to check the one that you’re actually trying to connect through.

In most cases your computer will discover the relevant DNS information over DHCP. If you’re using a static IP or something on your network is configured differently, you may have to set your DNS manually.

Systemd DNS Configuration

Open up “/etc/systemd/resolved.conf.” In that file uncomment the DNS line and add in either the IP of your router or another known DNS server. The default fallback DNS for Systemd is Google’s DNS servers listed under FallbackDNS.

If you’re using OpenRC or another Systemd alternative, you can find your DNS information in “/etc/resolv.conf.”

If there’s nothing there, enter in the IP address of your router or any other known DNS server that you’d prefer to use.

After either, restart networking or your entire computer.

The GUI Way

DNS GUI Configuration

If you’re using a graphical desktop with Network Manager, you can edit your connection information that way. Open the applet or go through your system settings. Select your connection and find the “IPv4” tab. Switch the connection to “Manual,” and manually enter in the IP address of your computer and the IP of your router as the gateway. Then, in the DNS field below, enter your router’s IP or the IP of another DNS server.

Incorrect Network or Host Configuration

There are several other configuration options that may be incorrect. Any of them would make it impossible for your computer to connect to the server.

First, make sure that your computer’s network configuration is correct. Double-check the configuration files themselves, and of course, see if you can connect to the Internet another way.

If you’re using a specific hostname to connect or you’ve set up specific hosts on either the server or the client, you need to make sure that both machines can connect to each other. Check the configurations of “/etc/hosts,” “/etc/hosts.allow.” “/etc/hosts.deny.”

Finally, check your server configuration. Something might be improperly configured on the server, preventing clients from connecting properly.

Once you’ve fixed your internet connection woes, why not celebrate by installing Mac’s Safari browser on Linux? We also have a guide for casting your Android screen to Linux. Give it a shot!

Nick Congleton Nick Congleton

Nick is a freelance tech. journalist, Linux enthusiast, and a long time PC gamer.


  1. I am sorry but:
    – wrong port
    – service down
    – DNS errors
    Will never lead to “No route to host” error.
    1st two will return “Connection refused”
    DNS error will return “Host not found”

    The tools you need would be:
    ip route show (check for errors in local routing table) or even better
    ip route get destIP

    and the ultimate tool for route check:
    traceroute [-n] destIP

    1. @Jetchko:
      Totally correct.
      I thought the same thing.

      Personally I like “mtr” instead of traceroute (it’s a combination of ping + traceroute).

      Routing issues can also occasionally be because of bad ethernet connections, and so another command to use would also be:
      tcpdump -nni

Comments are closed.