DNS HOWTO : A caching only name server.
Previous: Introduction.
Next: Starting named

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, especially if you're on a slow connection.

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


// Config file for caching only name server

options {
	directory "/etc/namedb";

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

	// query-source port 53;
};

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

zone "0.0.127.in-addr.arpa" {
        type master;
        file "localhost.rev";
};

The `directory' line tells named where to look for files. All files named subsequently will be relative to this. /etc/namedb is the standard directory according to the hier(7) manpage.

The file named /etc/namedb/named.root is named in this. /etc/namedb/named.root should contain something simular to this:


;
; There might be opening comments here if you already have this file.
; If not don't worry.
;
.			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	192.112.36.4
J.ROOT-SERVERS.NET.	5w6d16h IN A	198.41.0.10
K.ROOT-SERVERS.NET.	5w6d16h IN A	193.0.14.129
L.ROOT-SERVERS.NET.	5w6d16h IN A	198.32.64.12
M.ROOT-SERVERS.NET.	5w6d16h IN A	202.12.27.33
A.ROOT-SERVERS.NET.	5w6d16h IN A	198.41.0.4
H.ROOT-SERVERS.NET.	5w6d16h IN A	128.63.2.53
B.ROOT-SERVERS.NET.	5w6d16h IN A	128.9.0.107
C.ROOT-SERVERS.NET.	5w6d16h IN A	192.33.4.12
D.ROOT-SERVERS.NET.	5w6d16h IN A	128.8.10.90
E.ROOT-SERVERS.NET.	5w6d16h IN A	192.203.230.10
I.ROOT-SERVERS.NET.	5w6d16h IN A	192.36.148.17
F.ROOT-SERVERS.NET.	5w6d16h IN A	192.5.5.241

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 section in named.conf is the last zone. I will explain its use in a later chapter, for now just make this a file named localhost.rev in the subdirectory etc/namedb/:


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

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


search subdomain.your-domain.edu your-domain.edu
nameserver 127.0.0.1

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, in this case your own machine since that is where your named runs (127.0.0.1 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 foo.subdomain.your-domain.edu is tried first, then foo.your-fomain.edu, finally foo. If a client tries to look up sunsite.unc.edu, sunsite.unc.edu.subdomain.your-domain.edu is tried first (yes, it's silly, but that's the way it works), then sunsite.unc.edu.your-domain.edu, and finally sunsite.unc.edu. 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 subdomain.your-domain.edu, your machine then, is probably called your-machine.subdomain.your-domain.edu. 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:


search subdomain.your-domain.edu your-domain.edu other-domain.com

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. This is important, 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.

/etc/nsswitch.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. 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.

/etc/host.conf

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


order hosts,bind

If there is no `order' line you should add one. 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 127.0.0.1).

3.1. Starting named

3.2. Making it even better

3.3. Congratulations


DNS HOWTO : A caching only name server.
Previous: Introduction.
Next: Starting named