nslookup works with /etc/resolv.conf, ping and ssh don't

Solution 1:

Well, did you read the comments at the top of /etc/resolv.conf?

# Mac OS X Notice
#
# This file is not used by the host name and address resolution
# or the DNS query routing mechanisms used by most processes on
# this Mac OS X system.

The correct solution is to add the search domains via the Network panel in System Preferences as described here.

Solution 2:

I had the same problem. The solution I used was to create an /etc/resolver directory. Inside that directory, create a file named for each domain you wish to resolve for. Inside each file there should be two lines

nameserver 10.0.100.2
domain  home.cainmanor.com

The file above would be named /etc/resolver/home. It may need to be named home.cainmanor.com, but I can't test it right now.

Good luck!

Solution 3:

I believe, the problem lies within the searchdomains configuration: ping/ssh are trying to use gethostbyname2() which fails because named is not running anymore (in Lion at least) and /etc/resolv.conf with the configured searchdomains is thus ignored. /etc/hosts is the last resort for gethostbyname2() and thus ssh works again with proper entries in /etc/hosts. Should be fixed by Apple imho.

Manually adding the searchdomains one by one fixed it, see solution above.

Solution 4:

I get this issue every so often, when my Mac Book Pro (OS X version 10.10.1) has been asleep. Wake it up & I can't ssh using hostname of machines on my network (and ping doesn't work either). nslookup works fine. Can't see any relevant messages in /var/log. Just leave it a few minutes & hey presto it works again .....

Solution 5:

I answered this somewhere else, because it was a simple fix for me, and I couldn't find the answer that worked for me anywhere else.

After restarting mDNSResolver dozens of times as recommended on other threads:

sudo killall -HUP mDNSResponder

I finally tried something else. I disabled Wi-Fi and deleted all of my preferred networks. Then I reestablished the Wi-Fi connection and everything worked okay:

  1. Apple menu -> System Preferences -> Wi-Fi (on the left)
  2. 'Turn Wi-Fi Off' then select 'Advanced'
  3. Delete the Wi-Fi connection you're having trouble with (or all of them if you like). Do this by selecting the Wi-Fi network you want to delete and pressing "-"
  4. Click 'Apply' and 'OK'
  5. Turn Wi-Fi back on.
  6. Select your Wi-Fi network and log in again.

This is what finally worked for me. It probably should have been the first thing I tried, but I'm a Linux guy and I look at console fixes first.