SSH "Could not resolve hostname": what to check
This error comes before any connection. ssh was given a name, could not turn it into an address, and stopped. Nothing was sent to the other machine, so keys, passwords, ports and firewalls are not the problem yet.
This page describes standard OpenSSH and DNS behaviour. The commands are the usual ones, and wording differs between versions and platforms. We did not run them against a particular network for this page.
What the message means
ssh: Could not resolve hostname server.example.com: Name or service not known
The text after the colon comes from the system's name lookup and varies.
Common forms are Name or service not known,
Temporary failure in name resolution and, on macOS,
nodename nor servname provided, or not known. In all of them ssh
never had an address to connect to.
That separates it from the other early errors. A timeout, a refused connection, Network is unreachable or No route to host means ssh had an address and tried it. Permission denied, covered in SSH "Permission denied (publickey)", means the connection worked and login failed. This page is only about the step before all of those.
1. Look at the name you typed
Most of these are typing mistakes. Read the name in the error message, since that is the exact text ssh looked up, and compare it with the name you meant.
- A missing or extra letter, or a dot in the wrong place.
- A name copied with a trailing character such as a comma, a colon or a bracket.
-
The wrong part of the command. In
ssh user@hostthe name is after the@. A stray space can make ssh read a different word as the host. -
A short name such as
piornasthat worked on another network. Short names often resolve only because a network adds its own domain to them.
2. Check whether ssh_config changes the name
If your SSH config has a Host entry that matches what you typed,
the name ssh looks up can differ from the one on the command line. The
HostName line in that entry replaces it. A typo there fails the
same way, and the error will show the replaced name, not the one you typed.
To see what ssh will use, ask it to print the result without connecting:
ssh -G myserver | grep -i '^hostname'
To read the whole output instead of one line, the ssh -G output reader picks out the host name, port, user, key files and proxy from a paste. It runs in your browser and sends nothing.
With -v, ssh also lists the config files it read near the start
of the output. If you are not sure the output is the one you expect, the
ssh -v output reader checks a pasted log
for well-known messages and links the matching guide. It runs in your browser
and sends nothing.
3. Ask the resolver directly
If the name is spelled as intended, look it up without ssh in the way:
getent hosts server.example.com
dig +short server.example.com
getent uses the same lookup path as most programs on Linux, and
dig asks a DNS server directly. nslookup is a common
alternative where dig is not installed. On macOS and Windows the
tools differ, but the question is the same: does anything on this machine turn
this name into an address? Then read the result as one of three cases.
- The name does not exist. No record was ever published, the domain lapsed, or the record was removed. The lookup is answered, but with nothing. Check the spelling of the name in whatever dashboard or inventory you took it from, and the account that owns the domain.
- The name only exists on one network. Office, VPN and home networks often serve names that public DNS does not know. The same name works at your desk and fails on a hotspot or from home with the VPN off. Connect to that network, or use the address or a public name instead.
-
The resolver did not answer. The lookup timed out, or
reports that the server could not be reached. Look at your own connection
first: whether other sites load, whether a captive portal is waiting for a
login, and whether the DNS server in use is the one you expect. A message
such as
Temporary failure in name resolutionusually points here rather than at the name.
4. Try the address instead of the name
If you know the machine's address, connect to that:
ssh user@203.0.113.10
If the address works and the name does not, the name is the problem, and the checks above are where to stay. If the address also fails, you now get a different error, such as a timeout. That is a path problem, and the timeout and refused guide takes it from there. An address typed this way skips DNS only. It does not tell you the address is still the right one.
If the name used to work
A name that resolved yesterday and does not today usually means a record that went away, a domain or dynamic DNS account that lapsed, or a resolver in between with a problem. If the name pointed at a home or site connection, see dynamic DNS SSH not working for the ways that chain breaks.
If the machine is a RescueShell device
This error happens on your own machine, before anything reaches the device. A path that starts from the device, like the one RescueShell uses, does not make a name resolve on your laptop. Fix the name, or connect to an address you know, and that part is done.
What it can change is whether you need a public name at all. The agent on the device keeps an outbound HTTPS connection to our relay, so a shell does not depend on a hostname that points at the device, a port forward, or a public address. That needs the agent installed and running first. If the real trouble is that the device has no stable public name, see dynamic DNS to keep a name working, or SSH without port forwarding and SSH behind CGNAT for reaching a device that has no public address. If a shell does not open once the agent is installed, see the shell does not open.
Try it on one device
The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.