Sunday, July 26, 2009

setup bind on Macbook

A few things to remember before we start...
Capitalization is important!
Terminal commands are shown in orange, and preceded by a # prompt character (don't type that!).
Comments are shown below commands, and /* surrounded by comment markers */. Don't type the comments.
Text you should be pasting is in orange italics.
And now, the step-by-step...
Start a root Terminal session

Open a Terminal session and launch a root shell by typing sudo bash. The rest of the instructions assume every step is done in this root shell!

Set up your machine to run the BIND server.
# rndc-confgen > /etc/rndc.conf
/* creates rndc.conf and generates key */
# head -n 6 /etc/rndc.conf > /etc/rndc.key
/* parses the key into the proper file */
# pico -w /etc/named.conf
/* opens the BIND configuration file for editing in the text editor */
Add the following into the options section, where x.x.x.x represents the IP addresses of either your ISP, or other DNS servers, known to you (Google for DNS servers if you don't know of any):
forwarders {
x.x.x.x;
x.x.x.x;
};
Save the file and quit the editor. Hit Control-O, Enter, then Control-X.

Create StartupItem for DNS [10.4 only; otherwise jump to next step]

It seems as if Tiger has removed the (already disabled in Panther) DNS Server completely from StartupItems. We have to add it if running Tiger.
# cd /System/Library/StartupItems
# mkdir BIND
# cd BIND
# touch BIND; pico -w BIND
/* Create first of two files, then open it in text editor */
Copy the following into the file, save it, and exit:
#!/bin/sh

. /etc/rc.common

if [ "${DNSSERVER}" = "-YES-" ]; then
ConsoleMessage "Starting BIND DNS Server"
/usr/sbin/named
fi
$ touch StartupParameters.plist; pico -w StartupParameters.plist
/* Create and open second of two files needed */
Copy the following into the file,save it, and exit:
{
Description = "Local Caching DNS Server";
Provides = ("DNS Server");
OrderPreference = "None";
Messages =
{
start = "Starting BIND DNS Server";
stop = "Stopping BIND DNS Server";
};
}
$ chmod +x BIND
/* Make the script executable so it can actually be run */
Enable DNS on boot
# pico -w /etc/hostconfig
/* Open the file OS X reads to start services */
Change it to make DNSSERVER=-YES-. Here Tiger users will have to add this value; Panther users will simply change it to -YES-. Save the file and exit.

Finish up with root
# exit
/* End root shell */
Tell OS X to use your local DNS

Open System Preferences, then the Network preferences panel. Change your 'DNS Server' setting to 127.0.0.1 for all the connections you use. This step is crucial, as failing to do so will make all your hard work completely useless.

Finally, either reboot, or issue the following command in the terminal:
$ sudo /System/Library/StartupItems/BIND/BIND