Learn about AlwaysAppendSearchDomains in OSX (Mountain) Lion
You all know that when you define your own domain as "example.net", and you want to ping a host called "mailbox.example.net", you can just use the (non-qualified) hostname "mailbox". Eg: ssh mailbox
If you have a host called web01.production.example.net, weather or not you can use "web01.production" as a shortname depends on how your operating system is configured.
In Mac OSX (Mountain) Lion, the shortcut won't work. If the hostname you try to use has a . in it, OSX will always assume it's a FQDN (fully qualified domain name), and won't try to append your default search domain.
There is a way to change this behaviour, and involves changing a .plist file, so be sure to have a backup before you make any changes...
Here we go:
1) Backup /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
sudo cp /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist ~/com.apple.mDNSResponder.plist.backup
2) Edit mDNSResponder.plist to include the "-AlwaysAppendSearchDomains" setting. You can use any text editor you like, just don't forget to invoke it via sudo. If you know vi(m), that's probably the easiest way:
sudo vim /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
3) You need to add <string>-AlwaysAppendSearchDomains</string> to the ProgramArguments array. In my copy, it was around line 16. Eg:
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/mDNSResponder</string>
<string>-launchd</string>
<string>-AlwaysAppendSearchDomains</string>
</array>
4) Reload the mDNSResonder service:
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist
Written by Frank Louwers
Related protips
4 Responses
awesome. thank you for posting this.
I've put together a shell script to automate the fix (and an uninstaller if you need it later), here:
https://github.com/michthom/AlwaysAppendSearchDomains
This was to give out to less-technical users at work that might shy away from manually editing system files.
I have noticed weird behavior in some apps since turning this on. Mail.app mysteriously can't connect to some of my accounts after waking my laptop (haven't verified that it's 100% of the time yet), yet if I quit and restart it finds them fine. MacIrssi has a similar issue with the IRC servers I have configured to auto-connect. Neither of these things happened before.
I don't see anything in the logs, and I haven't done a packet trace yet. Just putting it out there in case others have had any weird connection issues using this fix.
[Edit: Almost forgot: The hosts it fails to connect to in the above examples are not in domains which are in my search list, and all are specified by FQDN. Oddly enough it seems like this -doesn't- affect hosts which are in my search list (even though they are specified by FQDN as well.]
What's the "-launchd" for? I'm running Mavericks and /System/Library/LaunchDaemons/com.apple.mDNSResponder.plist doesn't include "-launchd". Should I add it?