Skip to Content

3 ways to fix ping: cannot resolve Unknown host

“ping: cannot resolve Unknown host” is an error message that typically appears when the ping command is used to try and reach a hostname that cannot be resolved to an IP address. This can happen for a few reasons:

  • The hostname does not exist: The hostname may have been typed incorrectly or the host may no longer exist on the network.
  • DNS server is not working properly: The DNS server may be down or not configured correctly.
  • The hostname is not registered in the DNS: The hostname may not be registered in the DNS server and therefore cannot be resolved to an IP address.
  • Network connectivity issue: The system may not have internet access or there may be a problem with the router or network connection.

 

At first, I thought the problem might be with the website I was trying to reach. I started by checking my internet connection to make sure it was working properly.

I noticed that my computer was connected to the network but it did not fix the problem.

In the end, I found that the issue was related to the DNS server.

In this article, let’s dive into this issue and see how to fix it.

understanding ping: cannot resolve Unknown host

The ping command is a tool used to test network connectivity by sending ICMP echo request and measuring the round-trip time and packet loss.

When a computer needs to access another network host, it needs to know the IP address of that host.

The process of converting a hostname (e.g., www.example.com) to an IP address is called “DNS resolution.”

The computer sends a request to a DNS server to resolve the hostname to an IP address.

If the computer is unable to resolve the hostname, you will receive the error message “ping: cannot resolve Unknown host.”

hostname is typed correctly

If the hostname was typed incorrectly or if the host is no longer on the network, the ping command will not be able to resolve the hostname to an IP address, resulting in this error message ping: cannot resolve Unknown host.

So make sure to double-check the spelling of the hostname to ensure that it is correct.

If you can login the remote host, you can use hostname command to verify it. This command will display the current hostname of the system.

Check out this article if you need to change your hostname.

DNS server is working properly

You can try one or more of the following methods to make sure that the DNS server is configured correctly and that it is able to resolve hostnames to IP addresses.

Using the dig command: The dig command is used to query DNS servers for information. You can use this command to check the resolution of a specific hostname by running the command “dig google.com” in a terminal.

The command will return the IP address associated with the hostname along with other DNS record information.

% dig google.com

; <<>> DiG 9.10.6 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41563
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
;; QUESTION SECTION:
;google.com. IN A

;; ANSWER SECTION:
google.com. 0 IN A 74.125.24.139
google.com. 0 IN A 74.125.24.100
google.com. 0 IN A 74.125.24.101
google.com. 0 IN A 74.125.24.102
google.com. 0 IN A 74.125.24.113
google.com. 0 IN A 74.125.24.138

 

If you get a response, that means your DNS server is working properly. If there is no response, we need to change our DNS servers.

Checking the /etc/resolv.conf file: The /etc/resolv.conf file contains the IP addresses of the DNS servers that the system is configured to use.

You can check this file to make sure that the DNS server IP addresses are correct and that the file is not corrupted.

# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

Follow the blow steps to change your DNS server.

  • Open the /etc/resolv.conf file using a text editor with administrative privileges. sudo nano /etc/resolv.conf
  • Locate the line that starts with nameserver followed by the IP address of the current DNS server.
  • Replace the existing DNS server IP address with the IP address of the new DNS server.
  • Save the changes and exit the text editor.

 

hostname is registered in the DNS Server

If the DNS server is working properly, the next step would be to verify that the hostname record for your system is registered and configured correctly on the DNS server.

You can use the dig command to check the hostname record for your system by running the command “dig hostname” in a terminal.

Here is an example of how to use the “dig” command to look up information about a hostname:

dig example.com

This command will perform a DNS lookup for the hostname “example.com” and return information such as the IP address associated with the hostname,

If there is no DNS record for your hostname, you can use the /etc/hosts file.

The /etc/hosts file contains a list of hostnames and their corresponding IP addresses. You can open this file using a text editor and check for the hostname you are trying to verify.

By adding an entry to this file, you can resolve a hostname to an IP address without the need for a DNS server. This can be useful for resolving hostnames when DNS is not available.

To add an entry in the /etc/hosts file, follow these steps:

  • Open a terminal window and gain root access by running the command ‘sudo su -‘
  • Use a text editor such as nano or vi to open the /etc/hosts file. For example, you can run the command ‘nano /etc/hosts’
  • Add a new line at the bottom of the file with the following format: IP_address hostname aliases. For example, “192.168.1.100 myserver”
  • Save the changes to the file by pressing ‘Ctrl + X’ then ‘Y’ and ‘Enter’
  • Verify the changes by running the command ‘cat /etc/hosts’
  • Once you have added the entry in the /etc/hosts file, you can test it by using the ping command to test the hostname resolution

 

Lgui

Thursday 23rd of November 2023

If you have access to other devices on the same network, check if they are also experiencing DNS resolution issues. This can help identify if the problem is specific to your device or a broader network issue.

David Cao

Thursday 23rd of November 2023

Thanks for sharing this.

Edwin M

Thursday 23rd of November 2023

Temporarily change your DNS server to a public DNS, like Google DNS (8.8.8.8 and 8.8.4.4) or Cloudflare DNS (1.1.1.1), and check if the problem persists. This can help determine if the issue is with your default DNS server.

Changing DNS server fixed my issue. Thank you.