Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

In our local university network, I have (obtained by DHCP) the following setup in /etc/resolv.conf:

nameserver x.x.x.x
nameserver y.y.y.y

The settings are the same in System Preferences as well. The following problem occurs:

nslookup server

works, and is using one of the nameservers to correctly ask for If I try to ping however,

ping server

fails with unreachable host.


works. Manually adding server with the ip address obtained by nslookup to /etc/hosts makes ping work too, but this "solution" circumvents the nameservers and is thus not ideal (and I would have to add about 20 other entries as well). Any idea what is causing this? Why does ping not use the results of nslookup/the searchdomains?

ssh server

also fails, which is the real problem/inconvenience.

I already added AlwaysUseSearchDomains to mDNSResponder, but this fix only helps the problem when using

I'm using OS X Lion 10.7.3.

share|improve this question
Ping packets may be blocked by network equipment. Same thing with ssh packets - they may not want you to do what you do. – Thorbjørn Ravn Andersen Jan 23 '13 at 20:40
See solution below, that was not the issue. – tholu Jan 24 '13 at 20:35
"Unreachable host" means a network connectivity problem (or ICMP blocked), not DNS resolution problem – Daniel Serodio Aug 27 '14 at 18:47
up vote 2 down vote accepted

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.

share|improve this answer
I did. The search domains are automatically entered in the Network panel in System Preferences per DHCP configuration (and are thus greyed out and not changeable). The exact same values/configuration are/is found in /etc/resolv.conf. – tholu May 7 '12 at 8:04
I don't know what to tell you, then. I get both my Ethernet and WiFi settings via DHCP and can change my search domains via the System Preferences panel. – Old Pro May 7 '12 at 21:04
The searchdomains are correct in System Preferences and /etc/resolv.conf - the problem is, that ping and ssh aren't using it. If they would use the output of nslookup, everything would work fine, but somehow, they don't. They lookup /etc/hosts, though. – tholu May 8 '12 at 11:14
I manually added the searchdomains (although they were greyed out) one by one via System Preferences and now it works. Thanks! – tholu May 9 '12 at 10:53

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


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

Good luck!

share|improve this answer
I got it working by setting the searchdomains via System Preferences one by one, overriding the DHCP settings which OS X failed to parse correctly obviously. I couldn't try your solution, but thanks! – tholu May 9 '12 at 10:54
This approach works nicely for when your corporate VPN client does the wrong thing with respect to transient system preferences. – Peter Jul 17 '13 at 15:06

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.

share|improve this answer
When I add a search domain to my WiFi connection (which is configured via DNS) in OS 10.7.3 via the System Preferences -> Network panel, it is used by ping and ssh just as I would expect. I do not touch /etc/resolv.conf or /etc/hosts manually/directly, but the changes from System Preferences are reflected in /etc/resolv.conf automatically. OS X does a lot of things differently than other Unix systems and this is one of them. – Old Pro May 8 '12 at 16:48
Thanks, this got it working by adding the searchdomains manually one by one, see my comment on your suggested solution above. – tholu May 9 '12 at 10:52
Adding search domains did not fix the issues... Any one else got another solution? – user40235 Jan 23 '13 at 20:11
How did you add them? – tholu Jan 24 '13 at 20:34

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

share|improve this answer

Your Answer


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.