Cyberithub

Solved "ssh: Could not resolve hostname xxxx" error in Linux

Advertisements

In this article, we will see how to solve "ssh: Could not resolve hostname xxxx" error in Linux. Sometimes you might have observed that when you try to remotely connect a host using the hostname then you end up in having "ssh: Could not resolve hostname xxxx" error on the output. But if you try to connect the same host using its IP address instead of hostname then you are able to connect to that IP but not to the same host. These can happen due to multiple reasons.

You need to check the most suitable reason occurring in your case. Here we will go through all the possible reasons that can cause "ssh: Could not resolve hostname xxxx" error and the best steps that you can take to solve that error.

 

Solved "ssh: Could not resolve hostname xxxx" error in Linux

Solved "ssh: Could not resolve hostname xxxx" error in Linux

Also Read: Solved "WslRegisterDistribution failed with error: 0x80370114"

In my case, when I tried to connect the remote cyberhost using ssh root@cyberhost command then I noticed below ssh: Could not resolve hostname cyberhost: Temporary failure in name resolution error on the output as you can see below.

cyberithub@ubuntu:~$ ssh root@cyberhost
ssh: Could not resolve hostname cyberhost: Temporary failure in name resolution

 

Reason #1: Problem with the Hostname Resolution

To fix the above error, I have created an entry in /etc/hosts file mapping the remote host name to the IP address. This will make ssh check the hosts file before checking with the DNS Server for hostname resolution.

cyberithub@ubuntu:~$ sudo nano /etc/hosts
127.0.0.1 localhost
192.168.0.102 cyberhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

After putting the above entry, I again tried to connect cyberhost using ssh root@cyberhost command and this time I am able to connect successfully as you can see below.

cyberithub@ubuntu:~$ ssh root@cyberhost
The authenticity of host 'cyberhost (192.168.0.102)' can't be established.
ECDSA key fingerprint is SHA256:YUAj/JP3Uw5O8J4Z7iKqSEk5B6pgCOuNfcciXy51he4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'cyberhost,192.168.0.102' (ECDSA) to the list of known hosts.
root@cyberhost's password:
Last login: Tue Feb 14 09:19:43 2023

O @ @ Issabel is a product meant to be configured through a web browser.
@ @ O Any changes made from within the command line may corrupt the system
@ O O configuration and produce unexpected behavior; in addition, changes
O made to system files through here may be lost when doing an update.

To access your Issabel System, using a separate workstation (PC/MAC/Linux)
Open the Internet Browser using the following URL:


Your opportunity to give back: http://www.patreon.com/issabel

System load: 0.66 (1min) 1.00 (5min) 0.47 (15min) Uptime: 3 min
Asterisk: OFFLINE
Memory: [==========>--------------------------------------] 22% 401/1837M
Usage on /: [===========>-------------------------------------] 24% 12/50G
Swap usage: 0.0%
SSH logins: 2 open sessions
Processes: 195 total, 148 yours

 

Reason #2: Host Resolving to Invalid IP

If the hostname is already mapped to an IP Address in the Global DNS Server or to the local host file, then it might be possible that IP address of the host is now changed and the new assigned IP is currently not reachable may be due to lack of connectivity or the IP itself is not valid now. Regarding the older IP that you are able to connect could have assigned to some other host. You can run nslookup <host> command to query the DNS Server and check the address.

cyberithub@ubuntu:~$ nslookup cyberhost
Server: 192.168.0.146
Address: 192.168.0.146#53

Non-authoritative answer:
Name: cyberhost
Address: 192.168.0.106

Hope above given solution should be enough to solve your "ssh: Could not resolve hostname xxxx" error as well. Please let me know your feedback in the comment box !!

Leave a Comment