Run a caching-only name server

Dec 20, '01 11:59:56AM

Contributed by: dlandrith

This one is for you hacking nuts that do absolutely everything possible to optimize your OS X machine.

If you are on a broadband network, then you can slightly optimize your internet access by installing bind, the Berkeley Internet Name Domain server name server as a caching server.

Using this caching nameserver setup should give you instant dns lookups on (pretty much) any hostname that has been used by any application on your machine at any time since the last reboot. Thus, if you access ftp.xyz.com using Fetch, the nameserver will look up the hostname and store it, so that tomorrow when you access it with Internet Explorer the caching nameserver will return the lookup information instantly.

If you'd like to set this up on your machine, read the rest of the article.

[Editor's note: I have not tried this myself yet, and it's a relatively complex hint. I believe I didn't lose anything in the formatting process, but please post if you notice any errors.]

Start by downloading bind (since you won't be migrating, you might as well use the latest version, 9.2) from this link. Unpack it by typing the following:

tar -xzvpf bind-9.2.0.tar.gz
Then, change directories to the bind source directory that you just unstuffed:
cd bind-9.2.0
Next, su to root and type the root password ("su" then enter).

We are going to do the install under /usr/local/. If you do not already have a /usr/local directory, then make one:
mkdir /usr/local
bind uses autoconf, so that compilation is easy. Type the following:
./configure --prefix=/usr/local --mandir=/usr/local/share/man
After several minutes, it will have configured all the appropriate files.
Then type the following:
make
After about 45 minutes to an hour, the compilation will finish. All that is left to do is install. To install, type the following:
make install
This should only take a few minutes.

When installation is finished, bind will not start, because it does not have any of the configuration files. We are going to use configuration files that simply use localhost and the loopback address (127.0.0.1). We will leave everything else to the default values.

In a standard installation, there is a named.conf file, an rndc.conf file, and a namedb directory that contains localhost.rev file. We are going to install these into /usr/local/etc. If you do not already have a /usr/local/etc directory, create one now:
mkdir /usr/local/etc
You will also want to create the namedb directory at this point:
mkdir /usr/local/etc/namedb
Now, we will make the named.conf file. We will add more to it later, but for
now it should look like this:
options {
directory "/usr/local/etc/namedb"; // Working directory
pid-file "named.pid"; // Put pid file in working dir
};

// Provide a reverse mapping for the loopback address 127.0.0.1
zone "0.0.127.in-addr.arpa" {
type master;
file "localhost.rev";
notify no;
};
If you are not comfortable typing this file into your favorite console based text editor, then you can download a copy of this file, cd to the directory into which you've downloaded it, and move it into /usr/local/etc:
mv named.conf /usr/local/etc
Next, we will create the localhost.rev file. This file should look like this:
$TTL 86400
; $ORIGIN 0.0.127.in-addr.arpa.
@ IN SOA localhost.localdomain. dlandrith.mac.com. (
12 ; Serial number
172800 ; Refresh every 2 days
3600 ; Retry every hour
1728000 ; Expire every 20 days
172800 ; Minimum 2 days
)
;
IN NS localhost.
;
0 IN PTR loopback-net.
1 IN PTR localhost.
If you are not comfortable typing this file into your favorite console based text editor, then you can download a copy of this file, cd to the directory into which you've downloaded it, and move it into /usr/local/etc/namedb:
mv localhost.rev /usr/local/etc/namedb
Next we will create the rndc.conf file, and use it to suppliment the named.conf file. The rndc.conf file gets created automatically. You will change to the /usr/local/etc directory:
cd /usr/local/etc
Next, you will use rndc-confgen to generate the configuration. Because of a bug in the openBSD random device that Darwin uses, you'll need to type a bunch of nonsense to generate a key that rndc uses to connect to bind. Issue the following command:
/usr/local/sbin/rndc-confgen > rndc.conf
Now just type away until the console says "stop typing."

This will automatically generate the rndc.conf file. This rndc.conf file also contains some lines that must be added to your named.conf file. We can add them automatically with the following command (which illustrates at the same time what is very cool and what is kind of creepy about Unix):
tail -n10 rndc.conf | head -n9 | sed -e s/#\ //g >> named.conf
Now, you should be ready to start. First, we'll run in console mode. Type the following:
/usr/local/sbin/named -gc /usr/local/etc/named.conf
After spitting out some messages, it should end up with a line that ends simply "running."

Open another terminal and type the following:
/usr/local/sbin/rndc status
This should end by telling you that your server is up and running.

Now, we want to set your server to start at boot time, so that you don't need to open a terminal to run your dns server. Rather than explain how this is done, download and unstuff this file.

Open the terminal, su to root, and cd to the directory into which you downloaded the file (the directory above the unstuffed directory called "Bind") and type the following:
cp -r Bind /System/Library/StartupItems
Last, change the DNS entry in the Network panel of your System Preferences to 127.0.0.1 and reboot. You can test this by simply opening your web browser. If pages come up, then it works.

Comments (30)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20011220115956917