‘No Route to Host’ Error in Linux – What To Do
Have you come across the ‘No Route to Host’ while trying to reach a server on Linux? This service connection error may be annoying, but you can fix it once you identify the cause.
‘No Route to Host’ denotes a network problem, usually one which shows up when the server or host is not responding. This may happen because of network issues or because of an inappropriate setup.
We’ll cover how to troubleshoot and remedy your network situation in this article.
Are Your Network Settings Correct?
Before we look at the more specific causes for this problem, make sure that your network settings are correct. Can you connect to the web? Is your DNS properly configured?
- Let’s start by running this command to find out: systemd-resolve –status
- If you spot any DNS problems there, go back to your network configuration and redo it if you have to. If you are using a standard network with a dynamic IP, the DNS numbers should update automatically.
- To manually configure your DNS, go to Network Manager and manually enter the IP address in the IPv4 tab.
- If your Linux distribution doesn’t have a graphical desktop, go to “/etc/systemd/resolved.conf”, find the DNS line and change the numbers with the numbers of the DNS you want and make other configurations if you have to.
- Also, if you have set up a static IP, you may want to revert to a dynamic IP and let your network get the connection information through DHCP.
Don’t forget to restart your computer before trying to connect to the host again. If you are still getting ‘No Route to Host’ keep on reading.
Is the Host Server Online?
The next step is to check that the host you are trying to connect to is actually online. After all, one of the most frequent causes for the error is that the service isn’t running as a result of maintenance or some other issue.
If the service is not online, check whether the host is. Sometimes the service may have stopped or not been started to begin with, even if there’s nothing wrong with the server itself.
- Using systemd, run the command: sudo systemctl status servicename
If the service is running, you need to look for another cause.
Are You Connecting to the Right Port?
Double check any documentation the host may have provided. It’s a common practice for server managers to lock down ports that aren’t used to improve server security. Attackers often use common ports to target Linux services.
If you are trying to connect to your own server, you can trace back the service to the correct port. To do this, you need to install a security tool that can help you see open ports – NMAP.
Here are the commands for installing NMAP across different Linux distributions:
CentOS: yum install nmap
Debian: apt-get install nmap
Ubuntu: sudo apt-get install nmap
Once you’ve installed NMAP, check to see open ports with the following command: sudo nmap -sS target-server-ip
If you don’t have direct access to the server, you’ll have to contact the host. But before you do that, take a look at some of the other possible causes for the ‘No Route to Host’ error in Linux.
Is the Host Name Right?
You may also get the ‘No Route to Host’ error if your computer and the server you are trying to connect to use different host names. Both machines should be configured to connect to one another.
Apart from the usual hosts configuration, you want to pay attention to the hosts.deny and hosts.allow files in “/etc”. If you are trying to connect to a new server, make sure you get the hostname of the server right.
Is iptables Blocking the Connection?
iptables is pretty useful when you want to configure the Linux kernel firewall tables. The full control it gives you over traffic that comes in and out of your computer is great.
But through a simple configuration mistake, iptables could block the connection to the port you want to reach and give rise to the ‘No Route to Host’ error.
- First, print out a list of your iptables and its connections by typing sudo iptables -L and hitting Enter.
- To check whether iptables is to blame, run the following command: sudo iptables -S. This will allow you to see whether the iptables rules that you have set block the connection. You may have to add an accept rule to the default INPUT chain.
- To clear up the firewall rules for an external firewall, you can use this command: sudo iptables -F
As you can see, it may take a while to get to the bottom of the ‘No Route to Host’ error, but the steps above should help you. While it may look like a complex problem, often it’s the result of conflicting configurations or simple network issues.
Have you come across any other potential causes and fixes for this error? Drop us a comment and tell us about it.