Setting up name service

So you've decided to set up name service. Congratulations, you're locking horns with one of the fiercest UNIX daemons. O'Reilly and Associates even has a 418-page book, DNS and Bind, on this one, if you're really interested. For today's exercise, I'm just going to walk you through a few simple steps to get the named daemon running, and show you my sample configuration. You should just be able to plug in your own numbers and run with this. At the end, we'll test it out a bit. By the end, if you've survived (hopefully it will be easier for you than it was for me) you'll have something horrible to boast about to your Linux friends.

To start up this daemon, you need to edit a few files. The rc.inet2 file should start up named at boot time, but odds are good this has been commented out of your file since most people working on standalone machines or even in small networks just don't need this program taking up memory and resources. It should be turned on right after inetd (which handles telnet, ftp, and lots of other services) gets started. My named startup looks like this:

# Start the NAMED/BIND name server.
if [ -f ${NET}/named ]
 then
  echo -n " named"
  ${NET}/named
 fi
where NET was previously defined as /usr/sbin.

To see if named got started, you can use ps -ax. Somehwhere in the list of processes that produces you should see:

   45  ?  S     0:00 /usr/sbin/named
If it isn't there, check your installation. It is possible that you never installed the DNS/BIND package that includes named.

Now that named is running, we have to tell your machine to use it. That, fortunately, is simple. You have to edit the /etc/host.conf file, adding the word bind on the first line after order hosts. It should end up looking something like this:

order hosts bind
multi on
trim hypertype.com
For our next magic trick, we have to teach named that it has to rely on itself for names. The /etc/resolv.conf file tells named which servers to ask for names. This is a pretty simple file:
domain hypertype.com
nameserver 127.0.0.1
nameserver hypeserve 
Translated, this means "For the domain name hypertype.com, ask the loopback address (yourself) for name resolution. If that fails, try hypeserve (which is also yourself) for the name resolution." On a real network, you should have real multiple choices for these, so that if one server goes down there will be others to take up the slack. For this local network, it doesn't matter - if the server goes down, it's all gone anyway.

So now we have named running and it knows to ask itself for information. Now we have to tell it where to look. The /etc/named.boot file gives it a road map, if not the friendliest one:

;
;    boot file for name server
directory /var/named
; type     domain                source host/file          backup file
;cache      .	named.ca                  root.cache
primary    hypertype.com	named.hosts
primary    0.0.127.IN-ADDR.ARPA	named.local
primary    124.168.192.IN-ADDR.ARPA	named.rev
The directory line tells named to find its files in /var/named. (If this was connected to the net, the cache line would be uncommented so our machine could store numbers collected from all over the net locally.) The next three lines tell it where to find names and addresses for our local machines, in three different formats. The first one is simple enough. Primary means that this file is the main source of information for all hosts on hypertype.com. The next two lines are cryptic because of the reverse notation. The first is the loopback address, done with the loopback network address backwards and IN-ADDR.ARPA tacked on the end. The next one is our network address, backwards, with IN-ADDR.ARPA. For now, don't worry about what these numbers mean (see the bibliography for more information) and plug in your own numbers.

Now that we've told named to look for these files, we have to create them. This is a small bit of torture. Rumor has it that there's a program called hostcvt on the Net someplace that will take your /etc/hosts file and create "instant" named files for you, but I can't find it. Let's take a look at the /etc/hosts file and see what we have to deal with:

#
# hosts		This file describes a number of hostname-to-address
#		mappings for the TCP/IP subsystem.  It is mostly
#		used at boot time, when no name servers are running.
#		On small systems, this file can be used instead of a
#		"named" name server.  Just add the names, addresses
#		and any aliases to this file...
#
# For loopbacking.
127.0.0.1	localhost
# connections via ethernet
#ip number	full name with domain	local name - no net
192.168.124.2	hypeserve.hypertype.com	hypeserve
192.168.124.3	hypermac.hypertype.com 	hypermac
# End of hosts.
Now we have to translate these into the much weirder world of named configuration files. The first, and easiest, is the /var/named/named.hosts file. (You may have to create the /var/named folder.) Here's what mine looks like:
;  /var/named/hosts
; local hosts on hypertype.com
; origin is hypertype.com
;
@	IN	SOA	hypeserve.hypertype.com.	simon.hypertype.com. (
			1 	; serial
			86400 	;refresh once per day
			3600 	; retry: one hour
			3600000 ;expire:42 days
			604800 	;minimum, one week
			)
;identify hypeserve as nameserver
	IN	NS	hypeserve.hypertype.com.	
;
; local mail - hypeserve?
	IN	MX	10 hypeserve
; loopback address
localhost.	IN	A	127.0.0.1
;ethernet
hypeserve	IN	A	192.168.124.2
hypermac	IN	A	192.168.124.3
No, it's not simple. My advice on these files is simple: copy these ones, replacing the names and numbers with your own names and numbers (keep in mind that all the spacing between keywords here is created with tabs). They work, and if you want more information, check the bibliography and take a lot of aspirin. There is one strange thing on this file that we haven't mentioned before that I do need to explain. In the top left is a mysterious simon.hypertype.com. This is an email address for other admins to send complaints and comments to. It would normally be written simon@hypertype.com, but for this file you replace the @ sign with a dot. This net isn't connected to any other networks, but it's probably a good idea to put something there anyway. The next file, named.local, isn't much:
; named.local file - from TCP/IP System Admin p. 178
@	IN	SOA	hypeserve.hypertype.com.	simon.hypertype.com (
			1	;serial
			36000	;refresh 100 hours
			3600	;retry after 1 hour
			3600000	;expire
			36000	;default ttl
			)
	IN	NS	hypeserve.hypertype.com.
1	IN	PTR	localhost.
As you can see, I grabbed this one from the Hunt book in my bibliography. This just identifies localhost, the loopback address, to named. You can use this verbatim, just changing the names like you did for named.hosts.

The next file, named.rev is a little strange. It's similar to the others, but is designed to work in reverse:

; reverse mapping of IP addresses
; /var/named/named.rev
; Origin is 124.168.192.in-addr.arpa
;
@	IN	SOA	hypeserve.hypertype.com. simon.hypertype.com. (
			1	;serial
			86400	;refresh
			3600	;retry
			3600000	;expire
			604800	; minimum
			)
	IN	NS	hyperserve.hypertype.com.
;local
2	IN	PTR	hypeserve.hypertype.com.
3	IN	PTR	hypermac.hypertype.com.
The top part is pretty much like the other files, but the bottom numbers are a little odd. The only this file want to know is the last part of your network address, which for a type C address is just that last byte of the IP address. For hyperserve at 192.168.124.2, this is 2. For hypermac, at 192.168.124.3, this is 3. Simple enough? Plug in your own values.

Time for testing. The first way to do this is with nslookup, a command that makes the nameserver look up the IP number from a name or the name from a number. Here's what happens with mine.

hypeserve:~# nslookup hypeserve.hypertype.com
Server:  localhost
Address:  127.0.0.1

Name:    hypeserve.hypertype.com
Address:  192.168.124.2

hypeserve:~# nslookup hypermac.hypertype.com
Server:  localhost
Address:  127.0.0.1

Name:    hypermac.hypertype.com
Address:  192.168.124.3

hypeserve:~# nslookup 192.168.124.3
Server:  localhost
Address:  127.0.0.1

Name:    hypermac.hypertype.com
Address:  192.168.124.3
The server that responds is always localhost. The next part gives both the name and address of whatever we wanted to look up. Yours should work similarly. If some parts work and others don't, you may have typos in your configuration files, which can turn into a real horror. If it doesn't work at all, make sure named is running. Then, check /etc/resolv.conf, then /etc/named.boot and then your individual files.

Another simple way to test if your system is working is with our old friend netstat:

hypeserve:~# netstat -r
Kernel routing table
Destination     Gateway         Genmask         Flags Metric Ref Use    Iface
hypertype.com   *               255.255.255.0   U     0      0      168 eth0
loopback        *               255.0.0.0       U     0      0        3 lo
default         192.168.124.1   0.0.0.0         UG    0      0        0 eth0
Those numbers from what we did earlier have (mostly) been transformed into almost meaningful names. A Linux network is definitely friendlier once you've christened all your machines. (No, don't dump holy water on them.)

Move on to setting up NCSA httpd.

Back to the start of the Linux instructions

Copyright 1995 by Simon St.Laurent. All rights reserved. You may print this document for yourself or others at no charge, but commercial distribution without permission is prohibited.

Hypertype
448 West 25th Street #3
New York, NY 10001
hypertyp@panix.com
SimonStL@aol.com