13

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.

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

I'm using OS X Lion 10.7.3.

3
  • Ping packets may be blocked by network equipment. Same thing with ssh packets - they may not want you to do what you do. Commented Jan 23, 2013 at 20:40
  • See solution below, that was not the issue.
    – tholu
    Commented Jan 24, 2013 at 20:35
  • "Unreachable host" means a network connectivity problem (or ICMP blocked), not DNS resolution problem Commented Aug 27, 2014 at 18:47

5 Answers 5

4

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.

4
  • 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
    Commented May 7, 2012 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
    Commented May 7, 2012 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
    Commented May 8, 2012 at 11:14
  • 1
    I manually added the searchdomains (although they were greyed out) one by one via System Preferences and now it works. Thanks!
    – tholu
    Commented May 9, 2012 at 10:53
3

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!

2
  • 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
    Commented May 9, 2012 at 10:54
  • This approach works nicely for when your corporate VPN client does the wrong thing with respect to transient system preferences.
    – Peter
    Commented Jul 17, 2013 at 15:06
3

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.

1
  • This has worked like a charm for me after banging my head trying to solve this for a while. Thank you!
    – Temikus
    Commented May 14, 2023 at 4:07
1

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.

4
  • 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
    Commented May 8, 2012 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
    Commented May 9, 2012 at 10:52
  • Adding search domains did not fix the issues... Any one else got another solution?
    – user40235
    Commented Jan 23, 2013 at 20:11
  • How did you add them?
    – tholu
    Commented Jan 24, 2013 at 20:34
1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .