When I try to SSH to a host on the network named storage
, I get a DNS resolution failure:
$ ssh storage
ssh: Could not resolve hostname storage: Name or service not known
But when I query DNS with host, it works
$ host storage
storage has address 192.168.20.103
How is it that host
can find the IP but ssh
cannot?
ssh
andhost
resolve names following completely different paths, so it is not surprising that they yield different results sometimes, especially when the name to resolve is not a FQDN (hence the suggestion to use FQDNs everywhere.)You don’t mention anything about your OS and your system configuration, so I have to keep it general, with an eye on Linux: MacOS details are somewhat different, and Windows even more, but the general concepts are the same.
host
queries DNS, so basically it looks in/etc/resolv.conf
and queries the servers listed there, possibly attaching a domain name if the hostname is not already fully qualified. It ignores every other possible source, but beware that these days many systems run a local caching DNS server (usuallydnsmasq
) which reads/etc/hosts
and other sources before querying other DNS servers, so ifhost
queries that local server, results from/etc/hosts
can creep in.ssh
follows its own path. I will describe whatopenssh
does under Linux, other implementations differ. First it looks for host nicknames defined in config files (system-wide/etc/ssh/ssh_config
and per-user~/.ssh/config
), then it searches other sources in the order specified by thehosts:
directive in/etc/nsswitch.conf
. Say it is something like:this means: look in
/etc/hosts
and then query the DNS (/etc/resolv.conf
again). Other possible sources are the obsoletenis
andnetinfo
services, LDAP, active directory, you name them.To debug your particular case, you should follow the path your implementation of
ssh
follows and find out where it gets stuck.