Tuesday, November 14, 2006

Setting the DNS Domain Search Path

Although OS X has many features in common with Linux, sometimes looks can be deceiving. For example, under Linux I would set the DNS domain search path by editing /etc/resolv.conf and adding a line like
search department.company.com company.com
which would cause the system to search first for "host.department.company.com" then, if that fails, "host.company.com". Under OS X, you'll find that there are two "resolv.conf" files:
# locate resolv.conf
/private/etc/resolv.conf
/private/var/run/resolv.conf
but neither of them can actually be used to do what I described above, although the contents of the files looks like a regular resolv.conf file under Linux.

Since OS X 10.4, these resolv.conf files are just for informational purposes, and even though you can modify the files, many applications will ignore them. Fortunately, there's a convenient command-line tool for changing the underlying DNS settings. The networksetup command can do it for you, like this:
 /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup \
-setsearchdomains 'Built-in Ethernet' department.company.com company.com

According to this post it also seems to be possible to use scutil to do this, although I haven't tried it and it looks more complicated.

No comments: