问题原文
原帖链接 · jldugger · CC BY-SA 3.0
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?
社区高分解答
原帖链接 · Dario · CC BY-SA 3.0
ssh and host 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.
hostqueries DNS, so basically it looks in/etc/resolv.confand 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/hostsand other sources before querying other DNS servers, so ifhostqueries that local server, results from/etc/hostscan creep in.sshfollows its own path. I will describe whatopensshdoes under Linux, other implementations differ. First it looks for host nicknames defined in config files (system-wide/etc/ssh/ssh_configand 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:hosts: files dnsthis means: look in
/etc/hostsand then query the DNS (/etc/resolv.confagain). Other possible sources are the obsoletenisandnetinfoservices, 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.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
