Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
4  
Start getting into the habit of using FQDNs everywhere. If this is the first problem you've had along these lines, you're extraordinarily fortunate. These can be really hairy to track down, and it won't be your last. Here's a hint: storage is a live top-level domain on the Internet. – Michael Hampton 5 hours ago
    
Are you able to 'ssh' to 192.168.20.103? – IvanGoneKrazy 5 hours ago
    
Where have you define the hostname of 192.168.20.103? /etc/hosts? – Orphans 4 hours ago

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 theDNS, 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 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.