SSH stands for secure shell, and it is a security protocol that provides end-to-end encryption of data. SSH could not resolve hostname is an error message that occurs when the host system fails to resolve the IP address of the remote host provided with the ssh command. Ssh protocol is widely used to provide secure remote shell access.
The ssh command is used to connect to a remote host. The ssh command requires a hostname to connect to, which is then inquired from a DNS(Domain Name System) server that sends the IP address of the remote host the user is trying to login to. If, for some reason, if the hostname is not resolved, then the ssh could not resolve the hostname error message is displayed.
Understanding SSH
Secure Shell is an intermediate protocol that is implemented between the application layer and the transport layer of the Internet protocol stack. It works on top of the TCP protocol, ensuring reliable delivery and data integrity. To connect to a remote shell, use the ssh command and provide the username and the hostname of the remote host you are trying to connect. Public key cryptography is used to authenticate the user. The private key is stored in the user’s host, which provides authentication. The ssh could not resolve hostname is one of the common errors faced while using ssh.
SSH hostname resolution and DNS
The hostname provided in the ssh command has to be resolved to an IP address, i.e., the address of the remote host in computer-readable form. The hostname can be provided in the IP address form example, 192.168.43.89, or a name can be used instead of example.com, for example. A DNS server is used to resolve the hostname to an IP address. The string of characters provided as the hostname in the command is sent to the DNS server, which then, in turn, returns the IP address of the host.
If the host is unable to contact the DNS server or the DNS server doesn’t return a valid IP address in return then, ssh could not resolve the hostname error that occurs. The ssh could not resolve hostname can also happen due to the cached DNS data stored in the system. Frequently used Domain name addresses are stored in cache storage in the host system so that the system doesn’t need to enquire the DNS server every time it makes a request. If the cache data is outdated or the host’s IP has been charged, the cached data becomes useless and can cause problems like ssh could not resolve the hostname.
If you are receiving the ssh could not resolve the hostname error, then a few steps can be employed to resolve and avoid this error message. Consider the given steps to fix the ssh could not resolve the hostname error.
Check the hostname
Most of the basic and simple measures to avoid the ssh could not resolve hostname is to check whether the hostname you are using with the ssh command is correct or not. Using the wrong hostname or domain address might result in a Wrong DNS response or no valid response at all. Check your hostname address for typos and syntax errors of the command. If everything is correct but still getting the hostname does not resolve the error, then employ the following measures.
Clearing DNS Cache
Clearing the DNS cache might also help resolve the ssh could not fix the hostname error. After the DNS cached data is deleted, a new fresh DNS inquiry is sent to the DNS server for each request, which would be beneficial if the IP address of the host is changed. Follow the given steps to clear the DNS cache in Windows.
- Press Windows + R.
- Enter cmd in the serach box and hit enter.
- In the shell Enter the command ipconfig /flushdns.
- The DNS cache is not cleared.
- Try running the ssh command again.
For Ubuntu users, Enter the following command in the terminal to clear the DNS cache manually.
Editing the /etc/hosts file
If you are trying to connect to a remote host using ssh for the first time and getting a hostname error not resolved error in return, try editing the ssh hosts file and entering the username and hostname in the file. Employing the given steps to edit the hosts’ file and fix the ssh could not resolve the hostname error.
- Open the terminal emulator.
- Enter sudo nano /etc/hosts.
- Enter your root password.
- Now in the file, enter the IP address and hostname of your remote host.
- Press ctrl + O to save the file.
- Press ctrl + X to exit nano.
- Run the ssh command again.
SSh could not resolve hostname github.com
The ssh could not resolve hostname error can also show up while using the git version management program. The git uses the ssh while cloning a repository or pushing a remote repository. The issue can be fixed with the following steps.
- Try to ping the github.com using the ping github.com command. If the server responds then try to run the git command again after rebooting the system, it might be a normal network issue.
- If the issue persists, follow the steps mentioned above, such as clearing the DNS cache.
- Run the following command to restart the network manager in linux, which might help resolve the issue.
sudo service network-manager restart
SSH could not resolve hostname Gitlab
Gitlab is another popular open-source platform that is widely used in DevOps operations. “ssh: Could not resolve hostname gitlab.example.com: Temporary failure in name resolution” is the error message that is displayed while logging into the GitLab server. As the message itself suggests, this is a temporary failure in the name resolution, and chances would be resolved automatically after some time. But if the problem persists, follow the steps suggested above to make it work. You could also try adding ssh:// before the git URL to resolve the hostname issue.
git clone ssh://[email protected]:username/This_is_a_demo.git
SSH could not resolve hostname Gitbucket.org
Bitbucket is another open platform used to host git repositories online. The same hostname resolution problem can be encountered with gitbucket.org as with github.com. To resolve this issue, use the suggested methods and configure your .git config file. Open the config file in the .git folder for your project’s main directory. Change the remote directory listing as mentioned below (remove the ssh:// in the config file) and rerun the command.
url = ssh://[email protected]
//before
url = [email protected]
//after
FAQs on SSH Could Not Resolve Hostname
What is TCP?
It stands for Transfer Control Protocol. It is a transport layer protocol that ensures the reliable hosts-to-host delivery of the data packets.
What is the difference between git and GitHub?
Git is a version management program that keeps track of the changes in a project, While GitHub is an online platform where people can share their git repositories.
What is the Linux equivalent of ipconfig?
The Linux equivalent of the ipconfig command is ifconfig.
Conclusion
The ssh could not resolve hostname is a common error that any user can face. It is not that big of an issue. It simply happens when the ssh command fails to resolve the IP address of the provided hostname. In such situations clearing the DNS cache or editing the /etc/host file can help. This article provided you with the necessary measure and solutions to fix this error. In the end, we also mentioned what to do if you are receiving this error while using the git CLI.
Trending Now
-
Fixing Xtools XToolkit Installation Error
●March 3, 2023
-
Troubleshoot DeepMotion Preview Not Working: Tips and Tricks
by Dharam Nath Jha●March 3, 2023
-
Getting Virtwifi has No Internet Access? Here’s What to Do!
by Dharam Nath Jha●February 16, 2023
-
The Ultimate Guide to Fixing Wabbajack Failed Unknown Error
by Dharam Nath Jha●February 16, 2023
I have installed RasPi Raspbian, and now I can’t do ssh or git clone, only local host names are being resolved it seems. And yet ping works:
pi ~ $ ssh test.com
ssh: Could not resolve hostname test.com: Name or service not known
pi ~ $ git clone gitosis@test.com:test.git
Cloning into 'test'...
ssh: Could not resolve hostname test.com: Name or service not known
fatal: The remote end hung up unexpectedly
pi ~ $ ping test.com
PING test.com (174.36.85.72) 56(84) bytes of data.
I sort of worked around it for github by using http://github.com
instead of git://github.com
, but this is not normal and I would like to pinpoint the problem.
Googling for similar issues but the solutions offered was either typo correction, or adding domains to hosts file.
asked Feb 25, 2013 at 0:53
2
This sounds like a DNS issue. Try switching to another DNS server and see if it works.
OpenDNS
- 208.67.222.222
- 208.67.220.220
GoogleDNS
- 8.8.8.8
- 8.8.4.4
answered Feb 25, 2013 at 1:17
chirinoskychirinosky
4,4281 gold badge27 silver badges39 bronze badges
3
Try reseting te contents of the DNS client resolver cache.
(For windows) Fireup a command prompt and type:
ipconfig /flushdns
If you are a linux or mac user, they have their own way of flushing the dns.
answered Sep 29, 2016 at 4:36
OzeshOzesh
6,4061 gold badge25 silver badges23 bronze badges
Had the same error, I just needed to specify a folder:
localmachine $ git pull ssh://someusername@127.0.0.1:38765
ssh: Could not resolve hostname : No address associated with hostname
fatal: The remote end hung up unexpectedly
localmachine $ git pull ssh://someusername@127.0.0.1:38765/
someusername@127.0.0.1's password:
That error message is just misleading.
answered Apr 23, 2014 at 17:06
kungfoomankungfooman
4,4131 gold badge43 silver badges31 bronze badges
if you’ve a network-manager installed
check /etc/nsswitch.conf
if you’ve got a line
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4
remove the **[NOTFOUND=return]**
restart /etc/init.d/networking
the [NOTFOUND=return] prevents futher lookups if the first nameservwe doesn't respond correctly
answered Jul 10, 2013 at 10:01
Maybe this is a rare case, but in case your target server works on a non-standard port rather than 22 like mine, you need specify port like below:
ssh user@remote_server -p 2222
The port number should be passed to the command via -p
argument. The error «could not resolve hostname» ocurred when I tryied to connect in this way: ssh user@remote_server:2222
.
answered Apr 6 at 4:03
thinwathinwa
2853 silver badges9 bronze badges
This may be an issue with the proxy. Kindly unset and try.
git config --global --unset http.proxy
git config --global --unset https.proxy
Pang
9,481146 gold badges81 silver badges122 bronze badges
answered Jun 29, 2017 at 4:56
Some Minecraft players have encountered the ‘Can’t resolve hostname’ error when trying to join a server, forbidding them from joining any server.
Note: The ‘Can’t resolve hostname’ error means that the hostname you are trying to connect to cannot be resolved to an IP address.
After a deep investigation of this issue, we came up with a shortlist of possible culprits that cause this error to happen:
- Miswritten IP address – This error could appear if you’ve mistyped the address, even if you added one space between the numbers. You need to make sure that the IP address is written perfectly.
- Firewall blocking Minecraft – The Windows Firewall’s job is to protect your system from network-based threats, so is set by default to protect Minecraft, but this might be blocking the game to work properly. To fix this, you need to disable the Firewall for Minecraft from the Windows Firewall settings.
- Bad DNS Range – Another possibility that is known to cause this behavior for some users is a badly assigned DNS range. If this scenario is applicable, you can fix this issue by replacing your current DNS range with a more stable one.
Now that you are aware of all the possible causes that trigger this error, here is a list of methods that will help you get rid of the ‘Can’t resolve hostname’ error:
Make sure that the server’s IP address is written correctly
Before jumping straight to the fixes, some affected players suggest that you should double-check the server’s IP address to see if it is mistyped.
Make sure that there are no extra spaces or characters in the address you typed to confirm that this is not the problem.
After you are sure that the server’s IP address is typed correctly, try to access the server again to see if the issue still occurs.
If you’ve done that and the error still appears, check below the following method.
Disable Firewall for Minecraft
A few players suggest that you will fix the ‘Can’t resolve hostname’ error by disabling the Windows Firewall for Minecraft.
The Windows Firewall is used to protect your Windows system from network-based threats. You can always configure these Windows Firewall settings from the Control Panel settings.
If you don’t know how to do that, follow the next instructions:
- Press Windows key + R and type ‘control’, then press Enter.
Opening up the Control menu - Inside the Control Panel menu, search for Allow an app through Windows Firewall and access it.
Allowing an app through Firewall - After that, firstly you need to click on Change settings to give administrator permission. Through the list of apps search for Minecraft, then click on Remove to disable the firewall for Minecraft.
Configuring the allowed apps - Now test the game and if your problem is still occurring, check below the last method.
Edit the DNS server address
Some people recommend changing the DNS server address for your network to fix the ‘Can’t resolve hostname’ error. The DNS server is set by default to pick an address automatically, so you have to change that from the Settings.
A DNS server is a computer server that contains a database of public IP addresses and their associated hostnames, and in most cases serves to resolve, or translate, those names to IP addresses as requested.
Follow the next guide if you don’t know how to change the DNS server address:
- Use the taskbar search option to search for Network and access the first result.
View networks and tasks - Inside the Network and Sharing Center, click on Change adapter settings.
Changing the adapter settings - Now right click on the Network address you are using, then click on Properties.
Accessing the network properties screen - Through the list of items that appeared on your screen, search for Internet Protocol Version 4 (TCP/IPv6), highlight it and click on Properties.
Accessing the Properties screen of IPv4 - Now, click on the circle next to Use the following DNS server addresses, then insert the following codes inside the two boxes:
208.67.222.222 208.67.220.220
Adjusting the DNS servers - After that, click on OK and your ‘Can’t resolve hostname’ error will be fixed.
Kamil Anwar
Kamil is a certified MCITP, CCNA (W), CCNA (S) and a former British Computer Society Member with over 9 years of experience Configuring, Deploying and Managing Switches, Firewalls and Domain Controllers also an old-school still active on FreeNode.
You may get an error message when connecting to a machine that says ssh: Could not resolve hostname server: Name or service unknown. This might happen if you cannot connect wirelessly or don’t have enough signal strength for your device, but it can also occur because of typos in the command line prompt.
In this article, we’ll discuss how to fix it so you can reaccess your machine.
What is SSH?
Secure Shell (SSH) is an intermediate protocol between the application and transport layers of the Internet protocol stack. To create a connection to a remote shell, use the ssh
command providing the username and hostname of the remote server.
Authentication uses public key cryptography, storing a private key in the user’s host. The error ssh: Could not resolve hostname
is one of the most common errors encountered when using SSH.
How Does SSH Resolution With DNS?
To initiate a secure connection via SSH, a hostname must be resolved to an IP address. This can be done by providing the remote system’s IP address (e.g., 74.6.11.164) or its domain name (e.g., techcolleague.com).
A DNS server is used to translate the hostname into an IP address, and if this process fails, an error that reads “ssh could not resolve the hostname” may occur.
Additionally, systems will often store frequently-used domain names in their cache storage, so they don’t have to query a DNS server every time they attempt a request – but if this data is outdated or incorrect, it can lead to similar errors with SSH resolution.
Solution 1: Ping the Host
If you’re having difficulty connecting to a host via SSH, you should try pinging it using the ping command. If the host does not respond, it may be due to an issue on the server side.
If the host responds, there might be a network issue. Check if you can SSH to other hosts.
Solution 2: Check the Hostname
When trying to SSH to a server, verify your full command. You may be typing a command that the ssh program does not understand.
Here is an example of a command you may have run:
As you can see, the error is about not resolving the hostname myserver.
When you use the ssh program, the command you will use should be the following:
ssh [email protected]
ssh root@74.6.11.164
In the previous example, the user is root and hostname is myserver which is not a valid hostname. The correct example is shown you provide user as root and hostname as 74.6.11.164.
Solution 3: Fix the Hosts File
Hostname problems can also arise due to damage to the hosts file (i.e., /etc/hosts). Sometimes, ssh can give the same warnings for such errors as other issues. To edit the hosts file, root access is required.
Type the following command to open the file for editing:
sudo nano /etc/hosts
If you’re familiar with the vi program, you can also edit the file using vi by typing:
sudo vi /etc/hosts
The sudo prompt will ask for your password.
Make sure you have read and write access to the hosts file and look at the top of the file. You will need the following two lines for it to work correctly:
127.0.0.1 localhost
127.0.1.1 myhostname
Replace “myhostname” with your machine’s actual hostname. If you are working with an IPv6 network, you may also need these lines:
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
In most cases, correctly setting the first two lines is sufficient for networks that use only IPv4 technology. However, modern Internet connectivity is quickly moving towards the IPv6 standard, so you may need to set these additional lines in the future.
Your Linux distribution should have configured these settings for you, but errors can occur due to an errant package or user mistakes that corrupt the hosts file and direct connections to the wrong location.
Solution 4: Add an Entry in /etc/hosts
You may have a scenario where you want to specify myserver as your hostname because you don’t want to type the IP address 74.6.11.164. In this case, you need to add an entry in /etc/hosts.
To make this change, open the /etc/hosts file and add myserver line to the end of the file such as the following example:
Once this entry has been saved in /etc/hosts, you can ssh to the server by typing:
ssh [email protected]
You should not be able to connect to your specified server.
Solution 5: Check the Hosts Directive
If the previous solution didn’t fix your issue, it may be the ordering of the hosts directive in your /etc/nsswitch.conf file.
Take a look at your /etc/nsswitch.conf. It should have this line:
hosts: files dns
With the above line, your Linux system will look at files first, which is /etc/hosts to resolve DNS. If it finds nothing there, it will query DNS in /etc/resolv.conf.
If your /etc/resolv.conf shows a different entry than the above, you may consider updating it and then connect to your server again.
Frequently Asked Questions
What Should Be The Proper Format For The SSH Command?
What Is The Hosts Directive In /etc/nsswitch.conf?
The hosts directive in /etc/nsswitch.conf determines the order in which the system should look for host resolution.
What Is The Role Of /etc/resolv.conf In Resolving The Hostname?
/etc/resolv.conf contains information about the DNS servers used by the system for host resolution.
Conclusion
This article explains the steps to resolve the error “ssh: Could not resolve hostname.” The error can be caused due to various reasons like incorrect hostname or command line prompt, missing entry in /etc/hosts, or incorrect ordering of the hosts directive in /etc/nsswitch.conf.
This article provides solutions to fix the issue. By following these steps, you can successfully connect to your machine.
Ahem… dynamically changing the server’s hostname will likely cause a great many of the system daemons to malfunction, and often in ways that are not immediately apparent. The O/S expects the hostname to be set when the system is installed and remain unchanged. hostname
is almost always checked just once on process startup. There are other ways to switch versions on the fly however…
The easiest is to setup a level of indirection using symlinks…
You don’t need two servers for this. Instead, on the same directory level as the website’s «home» directory (i.e. /var/www
, hosted/server/html
, etc.) create a directory for each version of the site as in…
.../
.../v1.0
.../v1.1a
.../v1.1b
:
The v1.1a
and v1.1b
will be your alternating «LIVE» and «TEST».
Here comes the indirection…
Creating symlinks is very fast so you can probably recreate them when you want to swap versions with the site under light load without too much disruption.
The hosting service I’m basing this on requires the website «home» directory to be «html» as in…
/home/group/subgroup/myuserid/html
So we rename the html
directory the service gives us to a version directory like v1.1a
and create a symlink to it named html
.
With our symlinks set, the directory listing might look like…
.../
.../TEST -> v1.1b
.../html -> v1.1a
.../v1.0
.../v1.1a
.../v1.1b
Upon making changes to website files in the .../v1.1b
directory, we run a script that removes (Ubuntu has a safer unlink
command) and recreates the symlinks with «html» and «TEST» swapped as in…
.../
.../TEST -> v1.1a
.../html -> v1.1b
.../v1.0
.../v1.1a
.../v1.1b
Hope this helps.
2013-02-16 18:15:12 EST supplemental…
Today’s research reveals there’s a lot conflicting opinion about this it seems.
My own experience comes from spending a lot of time restoring Xwindows and Ubuntu «zeroconfig» functionality after changing the hostname, as a few of my notes from the incident indicate…
- Ubuntu-10.04
-
Net
- As of the May 2011 updates, network settings requirements have changed dramatically in order to support Zeroconf!
-
The main issue encountered has to do with the ‘hostname’ command.
- The method Ubuntu uses to maintain the hostname, ip address, etc. has changed.
- The /etc/hostname and /etc/hosts files are now the authority for all of these values
- There can no longer be multiple aliases for a host in /etc/hosts
- In /etc/hosts, the first name should be the Fully Qualified Domain Name (FQDN) — in other words, hostname.domainname.
-
SSH now sends the FQDN instead of just the host name, so /etc/hosts.allow must be changed from…
ALL: LOCAL
to..
ALL: LOCAL *.DORIS
-
Excerpt from http://www.oldapps.com/linux/ubuntu.php?old_ubuntu=35?changelog…
-
‘Avahi will always start even if a .local domain is present. The avahi-daemon package, which implements the mDNS «zeroconf» standard, formerly included a check to avoid running when a conflicting .local DNS domain is present, as it was reported that some ISPs advertise such a .local domain on their networks, leaving Ubuntu hosts unable to see names advertised on the local network (327362). In Ubuntu 9.10, avahi-daemon is started regardless. It is possible that this may cause other problems. If your network is configured this way, you can disable mDNS using the following command:’
sudo stop avahi-daemon
sudo sed -e ‘/^start/,+1s/^/#/’ /etc/init/avahi-daemon.conf
-
A couple of relevent articles…
-
Near the end of Linux Hostname Configuration is a discussion of
Xwindow considerations -
This technote from IBM.com on the «Effect of changing the IP address
or Hostname on ITM Component server» is a good example of the
machinations often required to get everything back in sync after a
hostname change.