Fixing OSX Lion DNS Search Domains

One unexpected consequence of upgrading to Lion is that suddenly my normal DNS search domains stopped working. We use multiple VLANs at work with their own DNS sub-domains based on the environment.

For example, we might have a www01.staging.internal.lan and a www01.prod.internal.lan. When using any command line tools like SSH, its normal to just use the host+environment to address them:

ssh erik@www01.staging

This is a very common seetup for corporate lans and our internal DHCP publishes the internal.lan part as a DNS search domain. Everything worked as expected until I upgrade to 10.7. Now any hosts lookups that have a “.” in them do not use the search domains.

After some searching for possible solutions, I ran across a thread here and another blog post here that described the same issue.

Here’s how to change the DNS lookup behavior to work as expected:

 

  1. Make a backup of /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
    sudo cp /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ~/com.apple.mDNSResponder.plist.original
  2. Edit com.apple.mDNSResponder.plist — its a plain text file, so I used vim but you can use whatever text editor you have handy. Don’t forget to use sudo.
    sudo vim /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
  3. Add <string>-AlwaysAppendSearchDomains</string>after line 16
            <key>ProgramArguments</key>
    	<array>
    		<string>/usr/sbin/mDNSResponder</string>
    		<string>-launchd</string>
                    <string>-AlwaysAppendSearchDomains</string>
    	</array>
  4. Now unload and reload the mDNSResponder service:
    sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
    sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist

Thats it — you should be able to perform DNS lookups the same way as always.


  • Pingback: Fix for broken search domain resolution in OSX Lion | Making It Scale

  • dan

    Thank you. That was more than I expected to have to do, but it does seem to work. Appreciate it.

  • Bob

    Woohoo, thanks! I was getting very sick of typing “.mycompany.com” and having to re-enter all my credentials in Chrome due to the different hostname…

  • Phil Regnauld

    Does one need to log out or restart something else than mDNSresponser ? Not working here…
    ps ax does show that mDNSresponder is running with the new flag:

    53538 ?? Ss 0:00.10 /usr/sbin/mDNSResponder -launchd -AlwaysAppendSearchDomains

  • http://suanaikyeo.com Suan

    Thanks a ton! Very curious to know what was Apple’s reasoning behind disabling this…

  • SK

    Thank you – worked great, but I needed to re-open terminal tab – it seemed cached dns query

  • Bruce Edge

    Was already the default on Lion 10.7.2

    Still have this problem:

    %> host cm-11
    cm-11.foo.com has address 192.168.199.71
    %> ssh cm-11
    ssh: Could not resolve hostname cm-11: nodename nor servname provided, or not known

    host, dig, and nslookup all work, but ssh, ping, ftp etc fail name lookups.

  • Danny

    Thank you for sharing this fix, I’ve always relied on my search path to find long named hosts and now my addiction can live on ;-)

  • RageCage

    Awesome! Was driving me nuts :) .

  • Nila Pihl

    Great!

    My Lion-VPN-DNS-problem is solved :)

    Thanks!

    /Nila

    My iPhone App Life Log™: http://itunes.apple.com/us/app/life-log/id477272126
    My music on MySpace: http://www.myspace.com/studiolila