Previous Next Contents

3. A caching only name server.

A first stab at DNS config, very useful for dialup users.

A caching only name server will find the answer to name queries and remember the answer the next time you need it. This will shorten the waiting time the next time significantly, esp. if you're on a slow connection.

First you need a file called /etc/named.conf. This is read when named starts. For now it should simply contain:

// Config file for caching only name server

options {
        directory "/var/named";

        // Uncommenting this might help if you have to go through a
        // firewall and things are not working out:

        // query-source address * port 53;

zone "." {
        type hint;
        file "root.hints";

zone "" {
        type master;
        file "pz/127.0.0";

The `directory' line tells named where to look for files. All files named subsequently will be relative to this. Thus pz is a directory under /var/named, i.e., /var/named/pz. /var/named is the right directory according to the Linux File system Standard.

The file named /var/named/root.hints is named in this. /var/named/root.hints should contain this:

.                       6D IN NS        G.ROOT-SERVERS.NET.
.                       6D IN NS        J.ROOT-SERVERS.NET.
.                       6D IN NS        K.ROOT-SERVERS.NET.
.                       6D IN NS        L.ROOT-SERVERS.NET.
.                       6D IN NS        M.ROOT-SERVERS.NET.
.                       6D IN NS        A.ROOT-SERVERS.NET.
.                       6D IN NS        H.ROOT-SERVERS.NET.
.                       6D IN NS        B.ROOT-SERVERS.NET.
.                       6D IN NS        C.ROOT-SERVERS.NET.
.                       6D IN NS        D.ROOT-SERVERS.NET.
.                       6D IN NS        E.ROOT-SERVERS.NET.
.                       6D IN NS        I.ROOT-SERVERS.NET.
.                       6D IN NS        F.ROOT-SERVERS.NET.

G.ROOT-SERVERS.NET.     5w6d16h IN A
J.ROOT-SERVERS.NET.     5w6d16h IN A
K.ROOT-SERVERS.NET.     5w6d16h IN A
L.ROOT-SERVERS.NET.     5w6d16h IN A
M.ROOT-SERVERS.NET.     5w6d16h IN A
A.ROOT-SERVERS.NET.     5w6d16h IN A
H.ROOT-SERVERS.NET.     5w6d16h IN A
B.ROOT-SERVERS.NET.     5w6d16h IN A
C.ROOT-SERVERS.NET.     5w6d16h IN A
D.ROOT-SERVERS.NET.     5w6d16h IN A
E.ROOT-SERVERS.NET.     5w6d16h IN A
I.ROOT-SERVERS.NET.     5w6d16h IN A
F.ROOT-SERVERS.NET.     5w6d16h IN A

VERY IMPORTANT: In some versions of this document the file contents listed here will have a couple of spaces or a tab before the first non blank character. These are not supposed to be in the file. Delete any leading space in the files you cut and paste from this HOWTO.

Remember what I said about leading spaces!

The file describes the root name servers in the world. This changes over time and must be maintained. See the maintenance section for how to keep it up to date.

The next line in named.conf is the primary line. I will explain its use in a later chapter, for now just make this a file named 127.0.0 in the subdirectory pz:

@               IN      SOA     linux.bogus. hostmaster.linux.bogus. (
                                1       ; Serial
                                8H      ; Refresh
                                2H      ; Retry
                                1W      ; Expire
                                1D)     ; Minimum TTL
                        NS      ns.linux.bogus.
1                       PTR     localhost.

Next, you need a /etc/resolv.conf looking something like this:


The `search' line specifies what domains should be searched for any host names you want to connect to. The `nameserver' line specifies the address of your nameserver at, in this case your own machine since that is where your named runs ( is right, no matter if your machine has an other address too). If you want to list several name servers put in one `nameserver' line for each. (Note: Named never reads this file, the resolver that uses named does.)

To illustrate what this file does: If a client tries to look up foo, then is tried first, then, finally foo. If a client tries to look up, is tried first (yes, it's silly, but that's the way it works) , then, and finally You may not want to put in too many domains in the search line, it takes time to search them all.

The example assumes you belong in the domain, your machine then, is probably called The search line should not contain your TLD (Top Level Domain, `edu' in this case). If you frequently need to connect to hosts in another domain you can add that domain to the search line like this:


and so on. Obviously you need to put real domain names in instead. Please note the lack of periods at the end of the domain names.

Next, depending on your libc version you either need to fix /etc/nsswitch.conf or /etc/host.conf. If you already have nsswitch.conf that's what we'll fix, if not, we'll fix host.conf.


This is a long file specifying where to get different kinds of data types, from what file or database. It usually contains helpful comments at the top, which you should consider reading, now. After that find the line starting with `hosts:', it should read

hosts:      files dns

If there is no line starting with `hosts:' then put in the one above. It says that programs should first look in the /etc/hosts file, then check DNS according to resolv.conf.


It probably contains several lines, one should starting with order and it should look like this:

order hosts,bind

If there is no `order' line you should stick one in. It tells the host name resolving routines to first look in /etc/hosts, then ask the name server (which you in resolv.conf said is at These two latest files are documented in the resolv(8) man page (do `man 8 resolv') in most Linux distributions. That man page is IMHO readable, and everyone, especially DNS admins, should read it. Do it now, if you say to yourself "I'll do it later" you'll never get around to it.

3.1 Starting named

After all this it's time to start named. If you're using a dialup connection connect first. Type `ndc start', and press return, no options. If that back-fires try `/usr/sbin/ndc start' instead. If that back-fires see the FAQ section. Now you can test your setup. If you view your syslog message file (usually called /var/adm/messages, but another directory to look in is /var/log and another file to look in is syslog) while starting named (do tail -f /var/log/messages) you should see something like:

(the lines ending in \ continues on the next line)

Feb 15 01:26:17 roke named[6091]: starting.  named 8.1.1 Sat Feb 14 \
  00:18:20 MET 1998 ^
Feb 15 01:26:17 roke named[6091]: cache zone "" (IN) loaded (serial 0)
Feb 15 01:26:17 roke named[6091]: master zone "" \
  (IN) loaded (serial 1)
Feb 15 01:26:17 roke named[6091]: listening [].53 (lo)
Feb 15 01:26:17 roke named[6091]: listening [].53 (ippp0)
Feb 15 01:26:17 roke named[6091]: Forwarding source address is [].1040
Feb 15 01:26:17 roke named[6092]: Ready to answer queries.

If there are any messages about errors then there is a mistake. Named will name the file it is in (one of named.conf and root.hints I hope :-) Kill named and go back and check the file.

Now it's time to start nslookup to examine your handy-work.

$ nslookup
Default Server:  localhost


If that's what you get it's working. We hope. Anything else, go back and check everything. Each time you change the named.conf file you need to restart named using the ndc restart command.

Now you can enter a query. Try looking up some machine close to you. is close to me, at the University of Oslo:

Server:  localhost


nslookup now asked your named to look for the machine It then contacted one of the name server machines named in your root.hints file, and asked its way from there. It might take tiny while before you get the result as it searches all the domains you named in /etc/resolv.conf.

If you ask the same again you get this:

Server:  localhost

Non-authoritative answer:

Note the `Non-authoritative answer:' line we got this time around. That means that named did not go out on the network to ask this time, it instead looked in it's cache and found it there. But the cached information might be out of date (stale). So you are informed of this (very slight) danger by it saying `Non-authorative answer:'. When nslookup says this the second time you ask for a host it's a sure sign that named caches the information and that it's working. You exit nslookup by giving the command `exit'.

Now you know how to set up a caching named. Take a beer, milk, or whatever you prefer to celebrate it.

Previous Next Contents