Strovent SystemsSign in
Reference

ssh "Could not resolve hostname": Name or service not known

ssh: Could not resolve hostname means the name never became an IP address, so nothing was sent. Check spelling, the full domain, VPN DNS and host:port typos.

ssh: Could not resolve hostname host.example.com: Name or service not known

The client asked the operating system to turn the name into an IP address, and the lookup failed. No connection was attempted and the server never saw anything, so nothing on the server needs to change.

The middle part is the exact name that was looked up. The end is the resolver's own reason, which tells you where to look.

What the reason means

  • Name or service not known (Linux) or nodename nor servname provided, or not known (macOS). The name does not exist in any source this device checked: the hosts file and the DNS servers it uses.
  • Temporary failure in name resolution (Linux). No DNS server answered. The network or the DNS server is down, not the name. Other names usually fail too.
  • No address associated with hostname (Linux). The name exists in DNS but has no address.
  • No such host is known. (Windows). The Windows wording for a name that cannot be found (Windows Sockets error 11001, host not found).

Common causes

  • A typo, or a letter that looks right but is not, such as 0 for o.
  • A short name. ssh build01 may work at the office, where the device adds the company domain to short names, and fail elsewhere. Use the full name, build01.example.com.
  • An internal name, off the VPN. Many company names exist only on the company's DNS servers. Connect the VPN first, then try again.
  • A port written into the name. ssh [email protected]:2222 looks up a host literally named host.example.com:2222. Give the port separately: ssh -p 2222 [email protected], or as a URI, ssh ssh://[email protected]:2222.
  • A nickname from another computer. A name defined with Host in ~/.ssh/config, or a line in /etc/hosts, only exists on the computer where it was written.

Check what is being looked up

A Host entry in ~/.ssh/config can replace the name you typed with its HostName value. To see the name ssh will actually use:

ssh -G build01 | grep -i '^hostname'

On Linux, test the lookup the same way ssh does it:

getent ahosts host.example.com

No output means the lookup fails outside ssh too. dig and nslookup ask DNS directly and skip /etc/hosts, so they can disagree with ssh. That disagreement is a clue that the name was only ever in a hosts file.

Fixes

  • Use the full name, or connect with the IP address: ssh [email protected].
  • Give the address a nickname in ~/.ssh/config:
Host build01
    HostName 192.0.2.10
    User user1
  • On a computer you control, add the name to /etc/hosts.
  • If many names fail with "Temporary failure", fix the network or DNS first.

On a phone or tablet there is no hosts file to edit. Use the full name or the IP address, and connect the VPN first if the host is on an internal network.

Sources

Spotted a mistake? Email [email protected].