Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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

search a.domain.com b.domain.com domain.com
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 server.a.domain.com. If I try to ping however,

ping server

fails with unreachable host.

ping server.a.domain.com

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. Any help is appreciated, thanks in advance!

PS: I already added AlwaysUseSearchDomains to mDNSResponder, but this fix only helps the problem when using server.foo.

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 at 18:47

3 Answers 3

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 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
1  
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 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!

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

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.