Chapter 6. Configuring Hosts

“They were indeed a queer-looking party that assembled on the bank—the birds with draggled feathers, the animals with their fur clinging close to them, and all dripping wet, cross, and uncomfortable.”

Now that you or someone else in your organization has set up nameservers for your zones, you’ll want to configure the hosts on your network to use them. That involves configuring those hosts’ resolvers, which you can do by telling the resolvers which nameservers to query and which domain names to search. This chapter covers these topics and describes configuring the resolver in many common versions of Unix and in Microsoft’s Windows 2000, 2003, and XP (which are basically the same).

The Resolver

We introduced resolvers way back in Chapter 2, but we didn’t say much more about them. The resolver, you’ll remember, is the client half of the Domain Name System. It’s responsible for translating a program’s request for host information into a query to a nameserver and for translating the response into an answer for the program.

We haven’t done any resolver configuration yet, because the occasion for it hasn’t arisen. When we set up our nameservers in Chapter 4, the resolver’s default behavior worked just fine for our purposes. But if we’d needed the resolver to do more than or behave differently from the default, we would have had to configure the resolver.

There’s one thing we should mention up front: what we’ll be describing in the next few sections is the behavior of the vanilla BIND 8.4.6 resolver in the absence of other naming services. Not all resolvers behave quite this way; some vendors still ship resolvers based on earlier versions of the BIND code, and some have implemented special resolver functionality that lets you modify the resolver algorithm. Whenever we think it’s important, we’ll point out differences between the behavior of the 8.4.6 BIND resolver and that of earlier resolvers, particularly the 4.8.3 and 4.9 resolvers, which many vendors were shipping when we last updated this book. We’ll cover various vendors’ extensions later in this chapter.

Resolver Configuration

So what exactly does the resolver allow you to configure? Most resolvers let you configure at least three aspects of the resolver’s behavior: the local domain name, the search list, and the nameserver(s) that the resolver queries. Many Unix vendors also allow you to configure other resolver behavior through nonstandard extensions to DNS. Sometimes these extensions are necessary to cope with other software, such as Sun’s Network Information Service (NIS); sometimes they’re simply value added by the vendor.[*]

Almost all resolver configuration is done in the file /etc/resolv.conf (this might be /usr/etc/resolv.conf or something similar on your host—check the resolver manual page, usually in section 4 or 5, to make sure). There are five main configuration directives you can use in resolv.conf: the domain directive, the search directive, the nameserver directive, the sortlist directive, and the options directive. These directives control the behavior of the resolver. There are other, vendor-specific directives available on some versions of Unix; we’ll discuss them at the end of this chapter.

The Local Domain Name

The local domain name is the domain name in which the resolver resides. In most situations, it’s the domain name of the zone in which you’d find the host running the resolver. For example, the resolver on the host toystory.movie.edu would probably use movie.edu as its local domain name.

The resolver uses the local domain name to interpret domain names that aren’t fully qualified. For example, when you add an entry such as:

relay bernie

to your .rhosts file, the name relay is assumed to be in your local domain. This makes a lot more sense than allowing access to a user called bernie on every host on the Internet whose domain name starts with relay. Other authorization files such as hosts.equiv and hosts.lpd work the same way.

Normally, the local domain name is determined from the host’s hostname; the local domain name is everything after the first “.” in the name. If the name doesn’t contain a “.”, the local domain is assumed to be the root domain. So the hostname asylum.sf.ca.us implies a local domain name of sf.ca.us, while the hostname dogbert implies a root local domain—which probably isn’t correct, given that there are very few hosts with single-label domain names.[*]

You can also set the local domain name with the domain directive in resolv.conf. If you specify the domain directive, it overrides deriving the local domain name from the hostname.

The domain directive has a very simple syntax, but you must get it right because the resolver doesn’t report errors. The keyword domain starts the line in column one, followed by whitespace (one or more blanks or tabs), then the name of the local domain. The local domain name should be written without a trailing dot, like this:

domain colospgs.co.us

In older versions of the BIND resolver (those before BIND 4.8.3), trailing spaces are not allowed on the line and will cause your local domain to be set to a name ending with one or more spaces, which is almost certainly not what you want. And there’s yet another way to set the local domain name—via the LOCALDOMAIN environment variable. LOCALDOMAIN is handy because you can set it on a per-user basis. For example, you might have a big, massively parallel box in your corporate computing center that employees from all over the world can access. Each employee may do most of her work in a different company subdomain. With LOCALDOMAIN, each employee can set her local domain name appropriately in her shell startup file.

Which method should you use—hostname, the domain directive, or LOCALDOMAIN? We prefer using hostname primarily because that’s the way Berkeley does it, and it seems “cleaner” in that it requires less explicit configuration. Also, some Berkeley software, particularly software that uses the ruserok() library call to authenticate users, allows short hostnames in files such as hosts.equiv only if hostname is set to the full domain name.

If you run software that can’t tolerate long hostnames, though, you can use the domain directive. The hostname command will continue to return a short name, and the resolver will fill in the domain from resolv.conf. You may even find occasion to use LOCALDOMAIN on a host with lots of users.

The Search List

The local domain name, whether derived from hostname or resolv.conf, also determines the default search list. The search list was designed to make users’ lives a little easier by saving them some typing. The idea is to search one or more domains for names typed at the command line that might be incomplete—that is, that might not be fully qualified domain names.

Most Unix networking commands that take a domain name as an argument, such as telnet, ftp, rlogin, and rsh, apply the search list to those arguments.

Both the way the default search list is derived and the way it is applied changed from BIND 4.8.3 to BIND 4.9. If your resolver is an older make, you’ll still see the 4.8.3 behavior, but if you have a newer model, including BIND 8.4.7,[*] you’ll see the improvements in the 4.9 resolver.

With any BIND resolver, a user can indicate that a domain name is fully qualified by adding a trailing dot to it.[*] For example, the trailing dot in the command:

%telnet ftp.ora.com.

means “Don’t bother searching any other domains; this domain name is fully qualified.” This is analogous to the leading slash in full pathnames in the Unix and MS-DOS filesystems. Pathnames without a leading slash are interpreted as relative to the current working directory, while pathnames with a leading slash are absolute, anchored at the root.

The BIND 4.9 and later search list

With BIND 4.9 and later resolvers, the default search list includes just the local domain name. So, if you configure a host with:

domain cv.hp.com

the default search list contains just cv.hp.com. Also, the search list is usually applied after the name is tried as-is—a change from earlier resolvers. As long as the argument you type has at least one dot in it, it’s looked up exactly as you typed it before any element of the search list is appended. If that lookup fails, the search list is applied. Even if the argument has no dots in it (that is, it’s a single label name), it’s tried as-is after the resolver appends the elements of the search list.

Why is it better to try the argument literatim first? From experience, BIND’s developers found that, more often than not, if a user bothered to type in a name with even a single dot in it, he was probably typing in a fully qualified domain name without the trailing dot. Better to see right away whether the name was a fully qualified domain name than to create nonsense domain names unnecessarily by appending the elements of the search list to it.

Therefore, with a 4.9 or newer resolver, a user typing:

%telnet pronto.cv.hp.com

causes pronto.cv.hp.com to be looked up first because the name contains three dots, which is certainly more than one. If the resolver doesn’t find an address for pronto.cv.hp.com, it then tries pronto.cv.hp.com.cv.hp.com.

A user typing:

%telnet asap

on the same host causes the resolver to look up asap.cv.hp.com first, because the name doesn’t contain a dot, and then just asap.

Note that application of the search list stops as soon as a prospective domain name turns up the data being looked up. In the asap example, the search list would never get around to looking up just plain asap if asap.cv.hp.com resolved to an address.

The BIND 4.8.3 search list

With BIND 4.8.3 resolvers, the default search list includes the local domain name and the domain names of each of its parent domains with two or more labels. Therefore, on a host running a 4.8.3 resolver and configured with:

domain cv.hp.com

the default search list contains first cv.hp.com, the local domain name; then hp.com, the local domain’s parent; but not com because it has only one label.[*] The name is looked up as-is, after the resolver appends each element of the search list, and only if the name typed contains at least one dot. Thus, a user typing:

%telnet pronto.cv.hp.com

causes lookups of pronto.cv.hp.com.cv.hp.com and pronto.cv.hp.com.hp.com before the resolver looks up pronto.cv.hp.com by itself. A user typing:

%telnet asap

on the same host causes the resolver to look up asap.cv.hp.com and asap.hp.com, but not just asap because the name typed (“asap”) contains no dots.

The search Directive

What if you don’t like the default search list you get when you set your local domain name? In all modern resolvers, you can set the search list explicitly, domain name by domain name, in the order you want the domains searched. You do this with the search directive.

The syntax of the search directive is very similar to that of the domain directive, except that it can take multiple domain names as arguments. The keyword search starts the line in column one, followed by a space or a tab, followed in turn by one to six domain names in the order you want them searched.[*] The first domain name in the list is interpreted as the local domain name, so the search and domain directives are mutually exclusive. If you use both in resolv.conf, the one that appears last overrides the other.

For example, the directive:

search corp.hp.com paloalto.hp.com hp.com

instructs the resolver to search the corp.hp.com domain first, then paloalto.hp.com, and then the parent of both domains, hp.com.

This directive might be useful on a host whose users access hosts in both corp.hp.com and paloalto.hp.com frequently. On the other hand, on a BIND 4.8.3 resolver, the directive:

search corp.hp.com

causes the resolver to skip searching the local domain’s parent domain when the search list is applied. (On a 4.9 or later resolver, the parent domain’s name usually isn’t in the search list, so this is no different from the default behavior.) This might be useful if the host’s users access hosts only in the local domain, or if connectivity to the parent nameservers isn’t good (because it minimizes unnecessary queries to the parent nameservers).

Tip

If you use the domain directive with a BIND 4.8.3 resolver and update the resolver to version 4.9 or later, users who relied on your local domain’s parent being in the search list may believe the resolver has suddenly broken. You can restore the old behavior by using the search directive to configure your resolver to use the same search list that it would have built before. For example, under BIND 4.9, BIND 8, or BIND 9, you can replace domain nsr.hp.com with search nsr.hp.com hp.com and get the same functionality.

The nameserver Directive

Back in Chapter 4, we talked about two types of nameservers: primary nameservers and slave nameservers. But what if you don’t want to run a nameserver on a host, yet still want to use DNS? Or, for that matter, what if you can’t run a nameserver on a host (because the operating system doesn’t support it, for example)? Surely, you don’t have to run a nameserver on every host, right?

No, of course you don’t. By default, the resolver looks for a nameserver running on the local host—which is why we could use nslookup on toystory.movie.edu and wormhole.movie.edu right after we configured their nameservers. You can, however, instruct the resolver to look to another host for name service. This configuration is called a DNS client in the BIND Operations Guide.

The nameserver directive (yep, all one word) tells the resolver the IP address of a nameserver to query. For example, the line:

nameserver 15.32.17.2

instructs the resolver to send queries to the nameserver running at the IP address 15.32.17.2 instead of to the local host. This means that on hosts not running nameservers, you can use the nameserver directive to point them at a remote nameserver. Typically, you configure the resolvers on your hosts to query your own nameservers.

However, since many nameserver administrators don’t restrict queries, you can configure your resolver to query someone else’s nameserver. Of course, configuring your host to use someone else’s nameserver without first asking permission is presumptuous, if not downright rude, and using one of your own usually gives you better performance, so we’ll consider this only an emergency option.

You can also configure the resolver to query the host’s local nameserver using either the local host’s IP address or the zero address. The zero address, 0.0.0.0, is interpreted by most TCP/IP implementations to mean “this host.” The host’s real IP address, of course, also means “this host.” On hosts that don’t understand the zero address, you can use the loopback address, 127.0.0.1.

Now what if the nameserver your resolver queries is down? Isn’t there any way to specify a backup? Do you just fall back to using the host table?

The resolver allows you to specify up to three (count ‘em, three) nameservers by using multiple nameserver directives. The resolver queries those nameservers, in the order listed, until it receives an answer or times out. For example, the lines:

nameserver 15.32.17.2
nameserver 15.32.17.4

tell the resolver to first query the nameserver at 15.32.17.2, and if it doesn’t respond, to query the nameserver at 15.32.17.4. Be aware that the number of nameservers you configure dictates other aspects of the resolver’s behavior, too.

Warning

If you use multiple nameserver directives, don’t use the loopback address! There’s a bug in some Berkeley-derived TCP/IP implementations that can cause problems with BIND if the local nameserver is down. The resolver’s connected datagram socket won’t rebind to a new local address if the local nameserver isn’t running, and consequently the resolver sends query packets to the fallback remote nameservers with a source address of 127.0.0.1. When the remote nameservers try to reply, they end up sending the reply packets to themselves.

One nameserver configured

If there’s only one nameserver configured, [*] the resolver queries that nameserver with a timeout of five seconds. The timeout is the length of time the resolver will wait for a response from the nameserver before sending another query. If the resolver encounters an error that indicates the nameserver is really down or unreachable, or if it times out, it doubles the timeout and queries the nameserver again. The errors that could cause this include:

  • Receipt of an ICMP port unreachable message, which means that no nameserver is listening on the nameserver port

  • Receipt of an ICMP host unreachable or network unreachable message, which means that queries can’t be sent to the destination IP address

If the domain name or data doesn’t exist, the resolver doesn’t retry the query. Theoretically, at least, each nameserver should have an equivalent “view” of the namespace; there’s no reason to believe one and not another. So if one nameserver tells you that a given domain name doesn’t exist or that the type of data you’re looking for doesn’t exist for the domain name you specified, any other nameserver should give you the same answer.[] If the resolver receives a network error each time it sends a query (for a total of four errors[]), it falls back to using the host table. Note that these are errors, not timeouts. If it times out on even one query, the resolver returns a null answer and does not fall back to /etc/hosts.

More than one nameserver configured

With more than one nameserver configured, the behavior is a little different. Here’s what happens: the resolver starts by querying the first nameserver in the list, with a timeout of five seconds, just as in the single nameserver case. If the resolver times out or receives a network error, it falls back to the next nameserver, waiting the same five seconds for that nameserver. Unfortunately, the resolver won’t receive many of the possible errors; the socket the resolver uses is “unconnected” because it must be able to receive responses from any of the nameservers it queries, and unconnected sockets don’t receive ICMP error messages. If the resolver queries all the configured nameservers to no avail, it updates the timeouts and cycles through them again.

The resolver timeout for the next round of queries is based on the number of nameservers configured in resolv.conf. The timeout for the second round of queries is 10 seconds divided by the number of nameservers configured, rounded down. Each successive round’s timeout is double the previous timeout. After three sets of retransmissions (a total of four timeouts for every nameserver configured), the resolver gives up trying to query nameservers.

In BIND 8.2.1, the ISC changed the resolver to send only one set of retries, or a total of two queries to each nameserver in resolv.conf. This was intended to reduce the amount of time a user would have to wait for the resolver to return if none of the nameservers was responding.

For you mathophobes, Table 6-1 shows what the timeouts look like when you have one, two, or three nameservers configured.

Table 6-1. Resolver timeouts in BIND 4.9 to 8.2

Nameservers configured

   

Retry

1

2

3

0

5s

(2x) 5s

(3x) 5s

1

10s

(2x) 5s

(3x) 3s

2

20s

(2x) 10s

(3x) 6s

3

40s

(2x) 20s

(3x) 13s

Total

75s

80s

81s

For BIND 8.2 and later resolvers, Table 6-2 shows the default timeout behavior.

Table 6-2. Resolver timeouts in BIND 8.2.1 and later

Nameservers configured

   

Retry

1

2

3

0

5s

(2x) 5s

(3x) 5s

1

10s

(2x) 5s

(3x) 3s

Total

15s

20s

24s

So if you configure three servers, the resolver queries the first server with a timeout period of five seconds. If that query times out, the resolver queries the second server with the same timeout, and similarly for the third. If the resolver cycles through all three servers, it doubles the timeout period and divides by three (to three seconds, 10/3 rounded down) and queries the first server again.

Do these times seem awfully long? Remember, this describes a worst-case scenario. With properly functioning nameservers running on tolerably fast hosts, your resolvers should get their answers back in well under a second. Only if all the configured nameservers are really busy, or if they or your network are down, will the resolver ever make it all the way through the retransmission cycle and give up.

What does the resolver do after it gives up? It times out and returns an error. Typically, this results in an error message like:

%telnet tootsie
tootsie: Host name lookup failure

Of course, it may take about 75 seconds before this message appears, so be patient.

The sortlist Directive

The sortlist directive is a mechanism in BIND 4.9 and later resolvers that lets you specify subnets and networks for the resolver to prefer if it receives multiple addresses as the result of a query. In some cases, you’ll want your host to use a particular network to get to certain destinations. For example, say your workstation and your NFS server have two network interfaces each: one on a standard 100 Mbps Ethernet segment, subnet 128.32.1/24, and one on a gigabit Ethernet segment, subnet 128.32.42/24. If you leave your workstation’s resolver to its own devices, it’s anybody’s guess which of the NFS server’s IP addresses you’ll use when you mount a filesystem from the server—presumably, the first one in a reply packet from the nameserver. To make sure you try the interface on the gigabit Ethernet first, you can add a sortlist directive to resolv.conf that sorts the address on 128.32.42/24 to the preferred position in the structure passed back to programs:

sortlist 128.32.42.0/255.255.255.0

The argument after the slash is the subnet mask for the subnet in question. To prefer an entire network, you can omit the slash and the subnet mask:

sortlist 128.32.0.0

The resolver then assumes you mean the entire network 128.32/16. (The resolver derives the default unsubnetted net mask for the network from the first two bits of the IP address.)

And, of course, you can specify several (up to 10) subnets and networks to prefer over others:

sortlist 128.32.42.0/255.255.255.0 15.0.0.0

The resolver sorts any addresses in a reply that match these arguments into the order in which they appear in the directive, and appends addresses that don’t match to the end.

The options Directive

The options directive was introduced with BIND 4.9 and lets you tweak several internal resolver settings. The first is the debug flag, RES_DEBUG. The directive:

options debug

sets RES_DEBUG, producing lots of exciting debugging information on standard output, assuming your resolver was configured with DEBUG defined. (Actually, that may not be a good assumption because most vendors compile their stock resolvers without DEBUG defined.) This is very useful if you’re attempting to diagnose a problem with your resolver or with name service in general, but very annoying otherwise.

The second setting you can modify is ndots, which sets the minimum number of dots a domain name argument must have for the resolver to look it up before applying the search list. By default, one or more dots will do; this is equivalent to ndots:1. The resolver first tries the domain name as typed as long as the name has any dots in it. You can raise the threshold if you believe your users are more likely to type partial domain names that will need the search list applied. For example, if your local domain name is mit.edu, and your users are accustomed to typing:

%ftp prep.ai

and having mit.edu automatically appended to produce prep.ai.mit.edu, you may want to raise ndots to 2 so that your users won’t unwittingly cause lookups to the root nameservers for names in the top-level ai domain. You could do this with:

options ndots:2

BIND 8.2 introduced four new resolver options: attempts, timeout, rotate, and no-check-names. attempts allows you to specify how many queries the resolver should send to each nameserver in resolv.conf before giving up. If you think the new default value, 2, is too low for your nameservers, you can boost it back to 4, the default value before BIND 8.2.1, with:

options attempts:4

The maximum value is 5.

timeout allows you to specify the initial timeout for a query to a nameserver in resolv.conf. The default value is five seconds. If you’d like your resolver to retransmit more quickly, you can lower the timeout to two seconds with:

options timeout:2

The maximum value is 30 seconds. For the second and successive rounds of queries, the resolver still doubles the initial timeout and divides by the number of nameservers in resolv.conf.

rotate lets your resolver use all the nameservers in resolv.conf, not just the first one. In normal operation, if your resolver’s first nameserver is healthy, it’ll service all your resolver’s queries. Unless that nameserver gets very busy or goes down, your resolver will never query the second or third nameservers in resolv.conf. If you’d like to spread the load around, you can set:

options rotate

to have each instance of the resolver rotate the order in which it uses the nameservers in resolv.conf. In other words, an instance of the resolver still queries the first nameserver in resolv.conf first, but for the next domain name it looks up, it queries the second nameserver first, and so on.

Note that many programs can’t take advantage of this because they initialize the resolver, look up a name, then exit. Rotation has no effect on repeated ping commands, for example, because each ping process initializes the resolver, queries the first nameserver in resolv.conf, and then exits before using the resolver again. Each successive invocation of ping has no idea which nameserver the previous one used—or even that ping was run earlier. But long-lived processes that send lots of queries, such as a sendmail daemon, can take advantage of rotation.

Rotation can also make debugging trickier. If you use it, you’ll never be sure which nameserver in resolv.conf your sendmail daemon queried when it received that funky response.

no-check-names, finally, allows you to turn off the resolver’s name checking, which is on by default.[*] These routines examine domain names in responses to make sure they adhere to Internet host-naming standards, which allow only alphanumerics and dashes in hostnames. You’ll need to set this if you want your users to be able to resolve domain names with underscores or nonalphanumeric characters in them.

If you want to specify multiple options, combine them on a single line in resolv.conf, like so:

options attempts:4 timeout:2 ndots:2

Comments

Also introduced with BIND 4.9 resolvers (and it’s about time, if you ask us), is the ability to put comments in the resolv.conf file. Lines that begin with a pound sign or semicolon in the first column are interpreted as comments and ignored by the resolver.

A Note on the 4.9 Resolver Directives

If you’re just moving to a BIND 4.9 resolver, be careful when using the new directives. You may still have older resolver code statically linked into programs on your host. Often, this isn’t a problem because Unix resolvers ignore directives they don’t understand. However, don’t count on all programs on your host obeying the new directives.

If you’re running on a host with programs that include really old resolver code that doesn’t understand the search directive (i.e., older than 4.8.3) but you still want to use search with programs that can take advantage of it, here’s a trick: use both a domain directive and a search directive in resolv.conf, with the domain directive first. Old resolvers will read the domain directive and ignore the search directive because they won’t recognize it. New resolvers will read the domain directive, but the search directive will override its behavior.

Sample Resolver Configurations

So much for theory—let’s now go over what resolv.conf files look like on real hosts. Resolver configuration needs vary depending on whether a host runs a local nameserver, so we’ll cover both cases: hosts with local nameservers and hosts with remote nameservers.

Resolver Only

We, as the administrators of movie.edu, have just been asked to configure a professor’s new standalone workstation, which doesn’t run a nameserver. Deciding which domain the workstation belongs in is easy: there’s only movie.edu to choose from. However, she is working with researchers at Pixar on new shading algorithms, so perhaps it’d be wise to put pixar.com in her workstation’s search list. The search directive:

search movie.edu pixar.com

makes movie.edu her workstation’s local domain name and searches pixar.com for names not found in movie.edu.

The new workstation is on the 192.249.249/24 network, so the closest nameservers are wormhole.movie.edu (192.249.249.1) and toystory.movie.edu (192.249.249.3). As a rule, you should configure hosts to use the closest nameserver available first. (The closest possible nameserver is a nameserver on the local host; the next closest is a nameserver on the same subnet or network.) In this case, both nameservers are equally close, but we know that wormhole.movie.edu is bigger (it’s a faster host, with more capacity). So the first nameserver directive in resolv.conf should be:

nameserver 192.249.249.1

Since this particular professor is known to get awfully vocal when she has problems with her computer, we’ll also add toystory.movie.edu (192.249.249.3) as a backup nameserver. That way, if wormhole.movie.edu is down for any reason, the professor’s workstation can still get name service (assuming toystory.movie.edu and the rest of the network are up).

The resolv.conf file ends up looking like this:

search movie.edu pixar.com
nameserver 192.249.249.1
nameserver 192.249.249.3

Local Nameserver

Next, we have to configure the university mail hub, postmanrings2x.movie.edu , to use domain name service. postmanrings2x.movie.edu is shared by all groups in movie.edu. We’ve recently configured a nameserver on the host to help cut down the load on the other nameservers, so we should make sure the resolver queries the nameserver on the local host first.

The simplest resolver configuration for this case is no configuration at all: don’t create a resolv.conf file, and let the resolver default to using the local nameserver. The hostname should be set to the full domain name of the host so that the resolver can determine the local domain name.

If we decide we need a backup nameserver—a prudent decision—we can use resolv.conf. Whether we configure a backup nameserver depends largely on the reliability of the local nameserver. A good implementation of the BIND nameserver will keep running for longer than some operating systems, so there may be no need for a backup. If the local nameserver has a history of problems, though—for example, it hangs occasionally and stops responding to queries—it’s a good idea to add a backup nameserver.

To add a backup nameserver, just list the local nameserver first in resolv.conf (at the host’s IP address or the zero address, 0.0.0.0—either will do), then one or two backup nameservers. Remember not to use the loopback address unless you know your system’s TCP/IP stack doesn’t have the problem we mentioned earlier.

Since we’d rather be safe than sorry, we’re going to add two backup nameservers. postmanrings2x.movie.edu is on the 192.249.249/24 network, too, so toystory.movie.edu and wormhole.movie.edu are its closest nameservers (besides its own). We’ll reverse the order in which they’re queried from the previous resolver-only example to help balance the load between the two.[*] And because we’d rather not wait the full five seconds for the resolver to try the second nameserver, we’ll lower the timeout to two seconds. The resolv.conf file ends up looking like this:

domain movie.edu
nameserver 0.0.0.0
nameserver 192.249.249.3
nameserver 192.249.249.1
options timeout:2

Minimizing Pain and Suffering

Now that you’ve configured your host to use DNS, what’s going to change? Will your users be forced to type long domain names? Will they have to change their mail addresses and mailing lists?

Thanks to the search list, much of this will continue working as before. There are some exceptions, though, and some notable differences in the way that some programs behave when they use DNS. We’ll try to cover all the common ones.

Differences in Service Behavior

As you’ve seen earlier in this chapter, programs such as telnet, ftp, rlogin, and rsh apply the search list to domain name arguments that aren’t dot-terminated. That means that if you’re in movie.edu (i.e., your local domain name is movie.edu, and your search list includes movie.edu), you can type either:

%telnet misery

or:

%telnet misery.movie.edu

or even:

%telnet misery.movie.edu.

and get to the same place. The same holds true for the other services, too. There’s one other behavioral difference you may benefit from: because a nameserver may return more than one IP address when you look up an address, modern versions of Telnet, FTP, and web browsers try to connect to the first address returned, and if the connection is refused or times out, for example, they try the next, and so on:

%ftp tootsie
ftp: connect to address 192.249.249.244: Connection timed out
Trying 192.253.253.244...
Connected to tootsie.movie.edu.
220 tootsie.movie.edu FTP server (Version 16.2 Fri Apr 26
    18:20:43 GMT 1991) ready.
Name (tootsie: guest):

And remember that with the resolv.conf sortlist directive, you can even control the order in which your applications try those IP addresses.

One oddball service is NFS. The mount command can handle domain names just fine, and you can put domain names into /etc/fstab (your vendor may call it /etc/checklist), too. But watch out for /etc/exports and /etc/netgroup. /etc/exports controls which filesystems you allow various clients to NFS-mount. You can also assign a name to a group of hosts in netgroup and then allow them access via exports using the name of the group.

Unfortunately, older versions of NFS don’t really use DNS to check exports or netgroup; the client tells the NFS server its identity in a Remote Procedure Call (RPC) packet. Consequently, the client’s identity is whatever the client claims it is, and the identity a host uses in Sun RPC is the local host’s hostname. So the name you use in either file needs to match the client’s hostname, which isn’t necessarily its domain name.

Electronic Mail

Some electronic mail programs, including sendmail, also don’t work as expected; sendmail doesn’t use the search list quite the same way that other programs do. Instead, when configured to use a nameserver, it uses a process called canonicalization to convert names in electronic mail addresses to fully qualified domain names.

In canonicalization, sendmail applies the search list to a name and looks up data of type ANY, which matches any type of record. sendmail uses the same rule newer resolvers do: if the name to canonicalize has at least one dot in it, check the name as-is first. If the nameserver queried finds a CNAME record (an alias), sendmail replaces the name looked up with the canonical name the alias points to and canonicalizes that (in case the target of the alias is itself an alias). If the nameserver queried finds an A record (an address), sendmail uses the domain name that resolved to the address as the canonical name. If the nameserver doesn’t find an address but does find one or more MX records, one of the following actions is performed:

  • If the search list has not yet been appended, sendmail uses the domain name that resolved to the MX record(s) as the canonical name.

  • If one or more elements of the search list have been appended, sendmail notes that the domain name is a potential canonical name and continues appending elements of the search list. If a subsequent element of the search list turns up an address, the domain name that turned up the address is the canonical name. Otherwise, the domain name that found the first MX record is used as the canonical name.[*]

sendmail uses canonicalization several times when processing an SMTP message; it canonicalizes the destination address and several fields in the SMTP headers.[]

sendmail also sets macro $w to the canonicalized hostname when the sendmail daemon starts up. So even if you set your hostname to a short, single-part name, sendmail canonicalizes the hostname using the search list defined in resolv.conf. sendmail then adds macro $w and all aliases for $w encountered during canonicalization to class $=w, the list of the mail server’s other names.

This is important because class $=w names are the only names sendmail recognizes, by default, as the local host’s name. sendmail will attempt to forward mail that’s addressed to a domain name it thinks isn’t local. So, for example, unless you configure sendmail to recognize all of the host’s aliases (by adding them to class w or fileclass w, as we showed in Chapter 5), the host will try to forward messages that arrive addressed to anything other than the canonical domain name.

There’s another important implication of class $=w, which is that sendmail recognizes only the contents of class $=w as the local host’s name in MX lists. Consequently, if you use anything other than a name you’re sure is in $=w on the right side of an MX record, you run the risk that the host will not recognize it. This can cause mail to loop and then be returned to the sender.

One last note on sendmail: when you start running a nameserver, if you’re running an older version of sendmail (before version 8), you should set the I option in your sendmail.cf file. Option I determines what sendmail does if a lookup for a destination host fails. When using /etc/hosts, a failed lookup is fatal. If you search the host table once for a name and don’t find it, it’s doubtful it’ll miraculously appear later, so the mailer may as well return the message. When using DNS, however, a lookup failure may be temporary, because of intermittent networking problems, for example. Setting option I instructs sendmail to queue mail if a lookup fails instead of returning it to the sender. Just add OI to your sendmail.cf file to set option I.

Updating .rhosts, hosts.equiv, etc.

Once you start using DNS, you may also need to disambiguate hostnames in your host’s authorization files. Entries that use simple, one-part hostnames will now be assumed to be in the local domain. For example, the lpd.allow file on wormhole.movie.edu might include:

wormhole
toystory
monsters-inc
shrek
mash
twins

If we move mash and twins into the comedy.movie.edu zone, though, they won’t be allowed to access lpd; the entries in lpd.allow allow only mash.movie.edu and twins.movie.edu. So we have to add the proper domain names to hostnames outside the lpd server’s local domain:

wormhole
toystory
monsters-inc
shrek
mash.comedy.movie.edu
twins.comedy.movie.edu

Here are some other files you should check for hostnames in need of domain-ification:

hosts.equiv
.rhosts
X0.hosts
sendmail.cf

Sometimes, simply running these files through a canonicalization filter—a program that translates hostnames to domain names using the search list—is enough to disambiguate them. Here’s a very short canonicalization filter in Perl to help you out:

#!/usr/bin/perl -ap
# Expects one hostname per line, in the first field (a la .rhosts,
# X0.hosts)

s/$F[0]/$d/ if ($d)=gethostbyname $F[0];

Providing Aliases

Even if you cover all your bases and convert all your .rhosts, hosts.equiv, and sendmail.cf files after you configure your host to use DNS, your users will still have to adjust to using domain names. Hopefully, their confusion will be minimal and more than offset by the benefits of DNS.

One way to make your users’ lives less confusing after configuring DNS is to provide aliases for well-known hosts that are no longer reachable using their familiar names. For example, our users are accustomed to typing telnet doofy or rlogin doofy to get to the bulletin board system run by the movie studio on the other side of town. Now they’ll have to start using doofy’s full domain name, doofy.maroon.com. But most of our users don’t know the full domain name, and it’ll be some time before we can tell all of them and they get used to it.

Luckily, BIND lets you define aliases for your users. All we need to do is set the environment variable HOSTALIASES to the pathname of a file that contains mappings between aliases and domain names. For example, to set up a system-wide alias for doofy, we can set HOSTALIASES to /etc/host.aliases in the system’s shell startup files and add:

doofy    doofy.maroon.com

to /etc/host.aliases. The alias file format is simple: the alias starts the line in column one, followed by whitespace and then the domain name that corresponds to the alias. The domain name is written without a trailing dot, and the alias can’t contain any dots.

Now when our users type telnet doofy or rlogin doofy, the resolver transparently substitutes doofy.maroon.com for doofy in the nameserver query. The message the users see now looks something like:

Trying...
Connected to doofy.maroon.com.
Escape character is '^]'.
IRIX System V.3 (sgi)
login:

If the resolver falls back to using /etc/hosts, though, our HOSTALIASES won’t have any effect. So we should also keep a similar alias in /etc/hosts.

With time, and perhaps a little instruction, the users will start to associate the full domain name they see in the telnet banner with the bulletin board they use.

With HOSTALIASES, if you know the domain names your users are likely to have trouble with, you can save them a little frustration. If you don’t know which hosts they’re trying to get to, you can let your users create their own alias files, and have each user point the HOSTALIASES variable in his shell startup file to his personal alias file.

Additional Configuration Files

In addition to configuring the resolver for DNS queries, you may be able to configure which service is used to obtain name and address information. The most common file used by vendors is nsswitch.conf, which we will cover here. Some vendors use irs.conf or netsvc.conf. Check your system’s manual pages for details on these files.

nsswitch.conf

/etc/nsswitch.conf is used to configure the order in which a number of different sources are checked. You select the database you want to configure by specifying a keyword. For naming services, the database name is hosts. The possible sources for the hosts database are dns, nis, nisplus, and files (which refers to /etc/hosts in this case). Configuring the order in which the sources are consulted is a simple matter of listing them after the database name in that order. For example:

hosts:  dns files

has the resolver try DNS (i.e., query a nameserver) first, then check /etc/hosts. By default, resolution moves from one source to the next (e.g., falls back to /etc/hosts from DNS) if the first source isn’t available or the name being looked up isn’t found. You can modify this behavior by specifying a condition and an action in square brackets between the sources. The possible conditions are:

UNAVAIL

The source hasn’t been configured (in DNS’s case, there is no resolv.conf file, and there is no nameserver running on the local host).

NOTFOUND

The source can’t find the name in question (for DNS, the name looked up or the type of data looked up doesn’t exist).

TRYAGAIN

The source is busy, but might respond next time (for example, the resolver has timed out while trying to look up a name).

SUCCESS

The requested name was found in the specified source.

For each criterion, you can specify that the resolver should either continue and fall back to the next source or simply return. The default action is return for SUCCESS and continue for all the other conditions.

For example, if you want your resolver to stop looking up a domain name if it receives an NXDOMAIN (no such domain name) answer, but to check /etc/hosts if DNS isn’t available, you can use:

hosts:  dns [NOTFOUND=return] files

The Windows XP Resolver

We’ll cover the resolver in Windows XP because most modern Windows resolvers—Windows 2000, Windows Server 2003—look similar and act similarly. This resolver can be a little tough to find; its configuration is well hidden. To get to it, click on Start, then Control Panel, then Network and Internet Connections, then Network Connections. This brings up the window shown in Figure 6-1.

Windows XP Network Connections
Figure 6-1. Windows XP Network Connections

Right-click on Local Area Connection and choose Properties. This brings up a window like the one shown in Figure 6-2.

Windows XP Local Area Connection Properties
Figure 6-2. Windows XP Local Area Connection Properties

Double-click on Internet Protocol (TCP/IP). This posts the basic resolver configuration window shown in Figure 6-3.

Basic Windows XP resolver configuration
Figure 6-3. Basic Windows XP resolver configuration

If you check the Obtain DNS server address automatically radio button, the resolver queries the nameservers that the local DHCP server tells it to use. If you check the Use the following DNS server addresses radio button, the resolver queries the nameservers you specify in the Preferred DNS server and Alternate DNS server fields.[*]

To get at more advanced resolver configuration, click on (what else?) the Advanced . . . button. Click on the DNS tab, and you’ll see the window in Figure 6-4.

Advanced Windows XP resolver configuration
Figure 6-4. Advanced Windows XP resolver configuration

If you’ve specified the addresses of nameservers to query in the basic resolver configuration window, you’ll see them again at the top of this window, under DNS server addresses, in order of use:. The buttons allow you to add, edit, remove, and reorder the nameservers listed. There doesn’t seem to be a limit to the number of nameservers you can list, but it doesn’t make much sense to list more than three.

The Windows XP resolver uses an aggressive retransmission algorithm first introduced in Windows NT 4.0 SP4: the resolver sends its first query to the first nameserver in the DNS Server Search Order. However, the resolver waits only one second before retransmitting the query and retransmits simultaneously to the first nameserver configured for each of the network adapters on the host. If after two more seconds the resolver doesn’t receive a response, it simultaneously queries all the nameservers configured for all of the host’s adapters—statically configured, configured via DHCP, whatever. If none of those nameservers responds in four seconds, the resolver retransmits to all the nameservers again. It keeps doubling the timeout and retransmitting for a total of 4 retransmissions and 15 seconds. (See the Windows 2000 DNS white paper, at http://www.microsoft.com/windows2000/docs/w2kdns.doc, for details.)

Since it’s possible, in these days of split namespaces, to get two different answers from two different nameservers, the Windows XP resolver temporarily ignores negative answers (no such domain name and no such data) while querying multiple nameservers. Only if it receives a negative answer from a nameserver configured for each interface does it return a negative answer. If the resolver receives even a single positive answer from a nameserver, it returns that.

Checking the Append primary and connection specific DNS suffixes radio button has the resolver use the primary DNS suffix and the connection-specific DNS suffixes as the search list. The DNS suffix specific to this connection is set in this window, in the field to the right of DNS suffix for this connection, or via a DHCP option sent by the DHCP server. The primary DNS suffix, on the other hand, is set in the Control Panel by clicking on System (from the Classic view), choosing the Computer Name tab, then clicking on Change . . ., then clicking on More . . . . This brings up the window shown in Figure 6-5.

Configuring the primary DNS suffix in Windows XP
Figure 6-5. Configuring the primary DNS suffix in Windows XP

To set the Primary DNS suffix of this computer, enter it in the field below that label. By default, on computers that are members of an Active Directory domain, the primary DNS suffix is set to the AD domain’s name.

The checkbox labeled Append parent suffixes of the primary DNS suffix (see Figure 6-4) configures the resolver to use a BIND 4.8.3-style search list derived from the primary DNS suffix. So if your primary DNS suffix is fx.movie.edu, the search list will contain fx.movie.edu and movie.edu. Note that connection-specific DNS suffixes aren’t “devolved” (in Microsoft’s words) into a search list, but if they’re configured, connection-specific suffixes are included in the search list.

Checking the Append these DNS suffixes (in order) button configures the resolver to use the search list specified in the fields below. As with the list of nameservers, you can add, edit, remove, and reorder these with the buttons and arrows.

Finally, it’s worth mentioning the two checkboxes at the bottom of the window. Register this connection’s addresses in DNS determines whether this client will try to use dynamic update to add an A record mapping its name to the address of this connection, and a PTR record mapping the address back to a name if it’s a statically configured address. Use this connection’s suffix in DNS registration controls whether that update will use the domain name associated with this connection or the primary DNS suffix for this computer.

This feature—automatic registration —is designed to ensure that the domain name of your Windows client always points to its current IP address, even if that address was delivered by a DHCP server. (For DHCP clients, the DHCP server actually adds the PTR record mapping the client’s IP address back to its domain name.) It’s also the death knell of WINS, the Windows Internet Name Service, the proprietary—and much maligned—Microsoft NetBIOS naming service. Once all your clients are running modern versions of Windows, they’ll all use dynamic update to keep their name-to-address mappings current, and you can drive a wooden stake through the heart of WINS. We discuss registration in more detail in Chapter 17.

Allowing clients to dynamically update zones presents certain, er, challenges, though, which we’ll explore in Chapter 17.

Caching

The Windows XP resolver stores every record it receives in a shared cache available to all programs on the system. The resolver also obeys the TTL field of resource records it caches, up to a maximum of 24 hours by default. So if a record specifies a TTL longer than that, the resolver rounds down to 24 hours. This maximum TTL is configurable with a Registry setting:

MaxCacheTtl
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesDNSCacheParameters
Data type: REG_DWORD

Default value: 86,400 seconds (= 24 hours)

The Windows XP resolver also supports negative caching. Windows XP caches negative responses for 15 minutes by default. This negative caching timeout is also configurable with a Registry setting:

MaxNegativeCacheTtl
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesDNSCacheParameters
Data type: REG_DWORD

Default value: 900 seconds (= 15 minutes)

To disable negative caching altogether, set this value to 0.

To view the resolver’s cache, use ipconfig /displaydns. To clear the cache, type ipconfig /flushdns. To disable caching on Windows XP, you can use the command:

C:> net stop dnscache

However, this lasts only until the next reboot. To disable caching permanently, go to Services (in the Administrative Tools program group) and set the DNS Client service’s Startup type to Disabled.

Subnet Prioritization

This feature is analogous to the BIND resolver’s address-sorting feature. When the resolver receives multiple address records for the same domain name, it examines the IP address in each record and adjusts the order of the records before returning the list to the calling application: any records with IP addresses on the same subnets as the host on which the resolver is running are moved to the top of the list. Since most applications use addresses in the order returned by the resolver, this behavior causes traffic to remain on local networks.

For example, Movie U. has two mirrored web servers on two different subnets:

www.movie.edu.   IN  A  192.253.253.101
www.movie.edu.   IN  A  192.249.249.101

Let’s say the resolver on toystory.movie.edu (192.249.249.3) sends a query and receives these records. It sorts the record with address 192.249.249.101 to the top of the list because toystory shares a network with that address.

Note that this behavior defeats the round-robin feature implemented by most nameservers. Round robin refers to the nameserver behavior of rotating the order of multiple address records in successive responses to distribute the load among the servers (again taking advantage of the behavior of most applications to use the first address in the list returned by the resolver). With subnet prioritization enabled, the order of the records is subject to shuffling by the resolver. You can disable subnet prioritization with a Registry setting:

PrioritizeRecordData
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesDNSCacheParameters
Data type: REG_DWORD
Range: 0 - 1
Default value: 1 (Subnet prioritization enabled)


[*] NIS used to be called “Yellow Pages” or “YP,” but its name was changed to NIS because the British phone company had a copyright on the name Yellow Pages.

[*] There are actually some single-label domain names that point to addresses, such as cc.

[*] Though the ISC added lots of new functionality to the nameservers in BIND 8 and 9, the resolver in these newer versions of BIND is nearly identical to the BIND 4.9 resolver.

[*] Note that we said that the resolver can handle a trailing dot. Some programs, particularly some mail user agents, don’t deal correctly with a trailing dot in email addresses. They choke even before they hand the domain name in the address to the resolver.

[*] One reason older BIND resolvers didn’t append just the top-level domain name is that there were—and still are—very few hosts at the second level of the Internet’s namespace, so tacking on just com or edu to foo is unlikely to result in the domain name of a real host. Also, looking up the address of a foo.com or foo.edu might well require sending a query to a root nameserver, which taxes the roots and can be time-consuming.

[*] BIND 9 resolvers actually support eight elements in the search list.

[*] When we say “one nameserver configured,” that means either one nameserver directive in resolv.conf or no nameserver directive and a nameserver running locally.

[] Caching and the latency of DNS’s zone transfer mechanism make this a small fib; cached records may differ temporarily from records in authoritative data, and a primary nameserver can have authority for a zone and have different data from a slave that also has authority for the zone. (The primary may have just loaded new zone data from disk, while the slave may not have had time to transfer the new zone data from its master. Both nameservers return authoritative answers for the zone, but the primary may know about a brand-new host that the slave doesn’t yet know about.)

[] Two for BIND 8.2.1 and newer resolvers.

[*] In all resolvers that support it, from BIND 4.9.4 on.

[*] Unless we were running a hidden primary. Of course, with our primary hidden, we’d probably want another secondary to help answer queries.

[*] All this complexity is necessary to deal with wildcard MX records, which we’ll discuss in Chapter 17.

[] Some older versions of sendmail use a different technique for doing canonicalization: they apply the search list and query the nameserver for CNAME records for the name in question. CNAME matches only CNAME records. If a record is found, the name is replaced with the domain name on the right side of the CNAME record.

[*] More kudos to Microsoft for clarifying its labels. In previous versions of Windows, nameservers were sometimes labeled Primary DNS and Secondary DNS. This sometimes misled users into listing the primary and slave (secondary) nameservers for some zone or another in those fields. Besides, “DNS” is an abbreviation for “Domain Name System,” not “domain nameserver.”

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset