How to Fix No Route to Host Error on Linux

Figuring out how to fix the no route to host error on Linux is essential for configuring network problems. And we are here to help you resolve the error in this guide. So read on. 

What Causes the No Route to Host Error on Linux?

Usually, the “No Route to Host” error occurs when there is a problem with the connectivity. Either the network setup is incorrect, or the Domain Name Server (DNS) has not been configured properly. In addition, the routing issues also cause this error. 

Apart from these situations, this error can also occur if the user is not connected to the network. 

How to Fix No Route to Host Error on Linux

Fixing the “No Route to Host” error on Linux can be a hassle if you don’t know the cause. In this section, we will cover several steps that will help you resolve this error easily. So, let’s get started:

Ping the Host Machine to Fix the No Route to Host Error on Linux

One of the common reasons you might get a “No Route to Host” error is that the server might be down. You can confirm it by running the ping command. If it runs smoothly, you must check for the other issues discussed in the following Method. To ping the server, type:

ping <server IP address>

The output should look something like this:

ping host

From the result, the server is running—otherwise, it would not ping. The server may be down for maintenance, or it might be experiencing issues. So you need to contact the owner of the server. 

Configure the DNS

The next Method to fixing the “No Route to Host” error is checking the DNS configurations. For this Method, use the system-resolve command. Open the Terminal by pressing “Ctrl + Alt + T” and type:

sudo systemctl systemd-resolve --status

Most Internet Service Providers (ISP) use a standard network with dynamic IP. Therefore, the DNS configures the IP automatically. To configure DNS manually, go to Network Manager from the Settings menu. 

Select Connections and locate the IPv4 tab. Change the connection type to Manual. Next, enter the IP Address in the IPv4 tab. Then, in the DNS field, type your router’s IP address or the DNS server you are using. 

Configure network

Save the configurations and restart the system to implement the changes. Once the system has rebooted, open the Terminal and execute the command given below:

sudo systemctl systemd-resolve –status

Alternatively, you can use the Terminal to set your IPv4 address manually. Open the file /etc/systemd/resolved.conf using the text editor:

# for nano editor
sudo nano /etc/systemd/resolved.conf
# for vim editor 
sudo vim /etc/systemd/resolved.conf

Uncomment the DNS line and add your IP address.

DNS=192.168.1.1
FallbackDNS=nameserver 192.168.1.1

Output:

Run iptable command

Save the configurations, exit the text editor and reboot the machine. 

Check the Host Service

Sometimes, the DNS is configured correctly, but the host machine is not running. This mostly happens due to maintenance issues. To check the host connections, use the systemctl command. For instance:

sudo systemctl status servicename

Check the Ports

The next Method is to check the ports for a smooth connection. For this Method, use the NMAP software to figure out which port is being used by the machine for the internet connection. In the Terminal, type:

sudo Nmap -sS target server-IP

To scan through all the ports, type:

sudo Nmap -sS target server-IP -p

The scan might take some time to finish, so be patient. 

Check the Hostname

Another method to fix the “No Route to Host” error is to check if your machine and the server have the same hostname. If the host names are different, you need to fix it. In addition, you must also check if the host machine has allowed the connection or not. For this, use the iptables command. For example:

sudo iptables -L

Output:

Fix no route to host error

Iptables utility allows Linux users to create filters to configure Linux farewell. These filters are listed as a table displaying what to do with traffic packets. 

Next, execute the following command to ensure your machine is not blocked on the network. 

Input:

sudo iptables -S

For a firewall check, use the -F option. Specifically, type:

sudo iptables -F

If the internal machine firewall is present, the network may cause blockage. To fix this, update the /etc/sysconfig/iptables file. Open the file using your favorite text editor. For instance, type:

#nano editor
sudo nano /etc/sysconfig/iptables

#vim editor
sudo vim /etc/sysconfig/iptables

Check for ports 111 and 2049 and enable them. Next, save the file and exit the editor by pressing “Ctrl + X” for the nano editor and ‘:q!’ for the vim editor. Lastly, check for the policies by using the -L option. Specifically, type:

sudo iptables -L

Output:

No route to host

Check for ip_conntrack_ftp Kernel Module

The above-discussed methods are used to connect to the machine. If you get the “No Route to Host” error while using the FTP server on Linux, it may be because of the missing ip_conntrack_ftp kernel module. To solve this problem, open the iptables file using the text editor. For example:

#nano editor
sudo nano /etc/sysconfig/iptables

#vim editor
sudo vim /etc/sysconfig/iptables

Next, add the following line at the end of the file:

IPTABLES_MODULES=”ip_conntrack_ftp”

Save the file, exit the editor and reboot your machine.

Check for the Port 22 for SSH

If you get the same error while using SSH on Linux, you must enable port 22 through the firewall. To configure the firewall rules, execute the command given below in the Terminal:

# For RHEL, CentOS or Fedora
firewall-cmd --permanent --add-port=22/tcp
firewall-cmd --reload
#For Debian and Ubuntu
sudo ufw allow 22/tcp
sudo ufw reload 

Output:

no route to host

Restart the machine and try using SSH once again to connect to the server machine. 

There are several reasons you might be getting the “No Route to Host” error on Linux. The network stack in Linux is pretty complicated, and figuring out the exact cause of the error is quite tricky for some. So make sure you follow through with the various methods discussed in this article to fix this error. 

Were you able to resolve the error in some other way? Drop your answers in the comment and tell us about them.

If this guide helped you, please share it.

Leave a Reply
Related Posts