Tumbled Logic

Feb 2

Using a local nameserver on Mac OS X redux

A long time ago, I wrote a post on using a local nameserver on Mac OS X. That was fine for 10.4, but 10.5 and 10.6 do things slightly differently.

First of all, although both client and server versions of Mac OS X ship with BIND, you shouldn’t use /etc/hostconfig to enable it any more. Have a look at /System/Library/LaunchDaemons/org.isc.bind.plist: by default the Disabled entry in the dictionary is set to <true/>.

By default, /etc/named.conf on Mac OS X doesn’t include a key for ‘rndc’. Have a look at ‘rndc-confgen’ and run ‘rndc-confgen -a’ if necessary (or run it without the -a and manually add the lines to your rndc.conf and named.conf).

You may wish to add a statement to the options stanza in /etc/named.conf: specifically, add listen-on port 53 { 127.0.0.1; };

This means that your private copy of BIND is visible to and can be queried by only you.

As this is a parallel nameserver, you don’t need to use the root hints or anything like that. Assuming you want to allow lookups for anything.localhost to resolve to 127.0.0.1, just remove all of the zone blocks except the one for localhost. Change the line which reads file "localhost.zone"; to read file "localhost-wildcard.zone";

Next, make a copy of /var/named/localhost.zone, calling it localhost-wildcard.zone in the same directory. Add the following two lines to the end:

* 1D IN A 127.0.0.1 * 1D IN AAAA ::1

You can then launch the nameserver via launchctl, or if you already have it running, reload the configuration and zones with rndc reload.

Now, assuming you’ve got your nameserver up and running and listening on port 53 of localhost, you should be able to verify that it works with the host utility: host test.localhost 127.0.0.1. If this times out or otherwise doesn’t return 127.0.0.1, go back and check that named is running and that it hasn’t reported errors via Console.app.

This guide to achieving the same thing as we’re trying to accomplish here may help you, but ignore the parts about modifying your resolv.conf or network configuration.

Next, create the directory /etc/resolver if it doesn’t exist and create a file in it named localhost. Add the following lines:

domain localhost nameserver 127.0.0.1.53 search_order 1

Finally, run dscacheutil - flushcache and try to ping test.localhost. If all is well, you should find your Mac pinging itself.


Page 1 of 1