大网数据广告活动
服务器运维问答

Why is SSH not resolving this hostname?

· 52CE 我爱测

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 s…

问题原文

原帖链接 · 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.

  • 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 (usually dnsmasq) which reads /etc/hosts and other sources before querying other DNS servers, so if host queries that local server, results from /etc/hosts can creep in.

  • ssh follows its own path. I will describe what openssh 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 the hosts: directive in /etc/nsswitch.conf. Say it is something like:

    hosts: files dns
    

    this means: look in /etc/hosts and then query the DNS (/etc/resolv.conf again). Other possible sources are the obsolete nis and netinfo 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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-02-10)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。