Have you come across ‘no route to host’ error while trying to reach a server on Linux? You can fix it once you identify the cause, join us on this article as we unravel possible causes and solutions.
Mostly ‘No route to host ‘ error on your Linux server indicates a network problem, or inappropriate network setup. It usually shows up when server or host is not responding. It means your computer can’t reach target server, either a local server or a remote server.
Step #1. Ensure network settings are correct
You can connect to the web of your DNS is properly configured. Run this command –Systemd-resolve-status. If you spot any DNS problem after running this command, then go back to your network configuration to reconfigure it.
To manually configure your DNS, go to network manager and manually enter IP address in the IPv4 tab. Otherwise if you’re using a standard network with a dynamic IP, the DNS number will update automatically.
If your Linux distribution does not have graphical desktop, go to “etc/systemd/resolved conf”, find the DNS line and change the numbers with the numbers of DNS you want and make other configurations as well. Also if you may want to setup a dynamic IP address, let your network go through connection information through DHCP.
You can restart your computer and try to connect to the host again. But if ‘no route to host ‘ error persists, then try next solution.
Step #2. Check if you are connected to the right port
Its common for server managers to lock down ports that does not improve their server’s security, attackers often use common ports to target Linux services so it’s understandable they have to lock it down.
Double check any documentation provided by the host. If you’re trying to connect to your own server,you can trace the service back to the correct port.
Install a security tool that can help you see open ports, use the following commands:
- CentOS-youm install nmap
- Debian-apt-get install nmap
- Ubuntu-sudo-apt-get install nmap
- Sudo nmap-sS target -server- IP
Once you install, check to see open ports with the command. If you still don’t have direct access to the server,you can contact the host.
Step #3. Check if host server is online or if service is running
Check that the host server you are trying to connect to is online, that’s usually one of the major causes for ‘no route to host ‘ error. Or that it’s not running because of maintenance, server is experiencing issues or it’s not online.
Using systemd, run the commands:sudo systemctl status service name to check if service is running and online. If it’s not, then it’s caused by something else.
Step #4. Check if host name is correct
If your computer and the server you are trying to connect to uses different host name. Both should be configured to connect to one another. Also pay attention to the host,if they allow files in “/etc”. Ensure you get host name of server right before connecting to avoid such error.
Step #5. Check if IPtables is blocking connection
IPtables are useful because they are user space utility programs that allows you configure your packet filter. When you want to configure Linux kernel firewall tables, it also gives you full control over traffic that comes in and out of your computer.
But a small configuration mistake, IPtables can block your connection to the port and causing a ‘no route to host’ error. You may have configured IPtables to block connections on that port.
To fix this, print out a list of your IPtables and it’s connections by typing the command: sudo-iptables-L and hit Enter.
Run the command: sudo-iptables-S, this command allows you see whether IPtables are to blame. If the rules have been set to restrict connections,then you have to add an accepted rule to default INPUT chain.
Then clear up the firewalls rules for external firewalls using the command: sudo-iptables-F.
No route to host error is a complex problem, it’s mainly a configuration or network related error. Simply double checking your network and configurations can help you fix it.
This article was first published on August 16, 2022 7:52 a.m. WAT
I am an experienced tech and innovation writer. It’s been 2 years+ I started writing at Terecle, covering mostly Consumer electronics and Productivity. In my spare time, I enjoy reading and learning the latest happenings around the tech ecosystem.