This post relates to pre-Leopard versions of Mac OS X. Unfortunately, Leopard hosts that are configured via DHCP use the DHCP assigned DNS server before any statically configured servers. Check out the next post in this series to find the necessary tweaks for Leopard.

If you've been following along in the OS X Caching Only Name Server series of articles, you should now have a running BIND daemon and be ready to start using it.

Setting a Localhost Name Server in OS XConfiguring an interface to use a local DNS server via the Network Panel in System Preferences is pretty straightforward. As you can see in this image (I've circled the change in red), you merely add '127.0.0.1' in the text box labeled 'DNS Servers:'. After applying the change, your BIND dns server running on 127.0.0.1 will be your primary DNS server.

If you need to make the change on a remote system, things are slightly more complicated. If you only have shell access (preferably via SSH), then you'll want to take some time to learn a bit about an application called ncutil.

The first thing you must realize about OS X network configuration is settings such as DNS are tied to network interfaces assigned to locations. Thus, if you have multiple locations, but want to make a setting change to the Built-in Ethernet interface, you have to make the change in each location. The default location is 'Automatic'. The very first thing we're going to do is take a look at the DNS values saved in the 'Automatic' location for our 'Built-in Ethernet' interface. As always, the '$' represents the shell prompt and should not be typed.

$ sudo ncutil read "Automatic/Built-in Ethernet/DNS"
$

As you can see, it doesn't return anything. This interface is configured to use DHCP and does not have any pre-configured DNS settings. OS X stores the DNS server settings in an array called 'name-server'. Using the ncutil command, we can add our local DNS server value ('127.0.0.1') to the 'name-server' array. Then, let's read the value back to verify the change. (Please note, each command should be on a single line. Formatting may cause a line to wrap on this page.)

$ sudo ncutil addval "Automatic/Built-in Ethernet/DNS" name-server 127.0.0.1
$ sudo ncutil read "Automatic/Built-in Ethernet/DNS"  
-rw       name-server = {
            127.0.0.1
          }

Perfect! Now we just need to save our changes so that the new settings will go into effect.

$ sudo ncutil apply-changes

That's all there is to it. You have successfully updated your OS X network settings to use a local DNS server.

Related Reading: