ssh: Could not resolve hostname sshdd: No address associated with hostname means
the SSH client could not find an address for the name you typed, so it never tried to
connect. In this test the name had a typo; getent hosts showed the wrong name
had no address and the right one had.
Correct the host name and connect again. If even a name you know is right fails, look at the machine's name resolution instead.
The error
$ ssh -o BatchMode=yes dev@sshdd true
ssh: Could not resolve hostname sshdd: No address associated with hostname
exit=255
Why it happens
Here the server container's name on the Docker network is sshd and the command said
sshdd. The Docker network's DNS had no such name and the client stopped with exit
code 255.
The text after the colon changes with the cause. The same command in a container started with
--network none, which has only a loopback interface, failed on a name that was
spelled correctly, with different wording:
$ ssh -o BatchMode=yes dev@sshd true
ssh: Could not resolve hostname sshd: Temporary failure in name resolution
exit=255
In these two runs, No address associated with hostname came from the client on
the Docker network with a mistyped name, and Temporary failure in name
resolution from the --network none container with the right name.
The fix
$ getent hosts sshdd
exit=2
$ getent hosts sshd
172.20.0.3 sshd
exit=0
$ ssh -o BatchMode=yes dev@sshd hostname
eed60eb6a2a1
exit=0
getent hosts looks a name up without SSH in the way: exit code 2 and no output
for the typo, an address for the real name. With the name corrected, the command logged in
and printed the server's host name (its container id). In the --network none
case the name was right: once that container was attached to the Docker network with
docker network connect, getent hosts sshd returned the address there
too.
How it was reproduced
Reproduced inside ubuntu:24.04 containers on Docker engine 29.9.3, with
OpenSSH_9.6p1 Ubuntu-3ubuntu13.20 installed by apt-get install -y openssh-client
openssh-server. The server container had the network alias sshd on a
user-defined Docker network and a test user dev; the client sat on the same
network, and a third container from the same image ran with --network none. The containers were removed afterwards.
Frequently asked
- What does ssh Could not resolve hostname No address associated with hostname mean?
- The client asked the system for the address of the host name and got none back. In this test the name had a typo and the DNS server did not know it.
- How do I check whether a host name resolves before using ssh?
- Run getent hosts followed by the name. An address in the output means it resolves; no output and exit code 2 means it does not.
- What is the difference between No address associated with hostname and Temporary failure in name resolution?
- In these tests the first came from a typo that the DNS server did not know, the second from a container started with --network none that could not reach any DNS server.
When the name resolves but nothing answers on port 22, see SSH: connect to host port 22: Connection refused. The same check for curl is in curl: (6) Could not resolve host. More decoded errors in the Fixes category.