The DNS Protocols
The DNS Protocols
by Craig Hunt
SYBEX, Network Press, and the Network Press logo are registered trademarks of SYBEX Inc.
Mastering, Expert Guide, Developer’s Handbook, and No experience required. are trademarks of SYBEX Inc.
TRADEMARKS: SYBEX has attempted throughout this book to distinguish proprietary trademarks from descriptive terms by
following the capitalization style used by the manufacturer.
Netscape Communications, the Netscape Communications logo, Netscape, and Netscape Navigator are trademarks of
Netscape Communications Corporation.
Microsoft® Internet Explorer ©1996 Microsoft Corporation. All rights reserved. Microsoft, the Microsoft Internet Explorer logo,
Windows, Windows NT, and the Windows logo are either registered trademarks or trademarks of Microsoft Corporation in
the United States and/or other countries.
The author and publisher have made their best efforts to prepare this book, and the content is based upon final release soft-
ware whenever possible. Portions of the manuscript may be based upon pre-release versions supplied by software manufac-
turer(s). The author and the publisher make no representation or warranties of any kind with regard to the completeness or
accuracy of the contents herein and accept no liability of any kind including but not limited to performance, merchantability,
fitness for any particular purpose, or any losses or damages of any kind caused or alleged to be caused directly or indirectly
from this book.
Photographs and illustrations used in this book have been downloaded from publicly accessible file archives and are used in
this book for news reportage purposes only to demonstrate the variety of graphics resources available via electronic access.
Text and images available over the Internet may be subject to copyright and other rights owned by third parties. Online avail-
ability of text and images does not imply that they may be reused without the permission of rights holders, although the
Copyright Act does permit certain unauthorized reuse as fair use under 17 U.S.C. Section 107.
Copyright ©2000 SYBEX Inc., 1151 Marina Village Parkway, Alameda, CA 94501. World rights reserved. No part of this pub-
lication may be stored in a retrieval system, transmitted, or reproduced in any way, including but not limited to photocopy,
photograph, magnetic or other record, without the prior agreement and written permission of the publisher.
The DNS Protocols
2
A protocol is a set of rules that define how two computers should interact to
exchange information over a network. Exchanging DNS data requires a set of standardized
protocols. Like any distributed database, DNS clients need to retrieve information from the
database and servers need to keep the information in the database accurate and up to date.
Queries require the exchange of questions and answers in agreed-upon formats. Synchro-
nizing databases among distributed servers requires an agreement on when and how the
synchronization is to be done.
The technical details of protocols and packet structure can be complex and intimidating,
particularly if your background is system administration and not network design. A pro-
tocol designer would probably feel the same way if asked to read one of your shell scripts.
If this chapter is not your cup of tea, feel free to jump ahead to more practical chapters. But
if you do, I urge you to come back and read this chapter after you have worked with DNS
configuration. You will find an elegant linkage between the actions you take in configuring
your system and the packets your system puts on the network.
This chapter tells you the rules that DNS uses to exchange information, not so you can
master the protocols but so you can master the DNS servers that depend on these proto-
cols. Understanding how data moves through the network helps in understanding why cer-
tain configuration parameters are required and what can be done to optimize them. Let’s
begin by understanding the protocol suite that DNS is part of.
DNS
UDP TCP
IP
The only time DNS uses TCP is when distributed servers synchronize their databases by
within the DNS hierarchy, even when the first server queried cannot provide a
real answer to the question.
Additional The additional section is found in a response. This section contains
database records that provide additional, important information that supports
the answer. These are not database records directly requested by the query, but
they help in interpreting or utilizing the response.
The format of the DNS message is clearly shown by the dig test tool. dig is one of the
DNS test tools included with Linux. It is used throughout this text and covered exten-
sively in Chapter 11, “Testing DNS.” A nice feature of dig is that it shows the entire DNS
message, not just the answer to the query. Listing 2.1 shows the DNS message format, as
displayed by dig.
;; ANSWER SECTION:
dog.mammals.org. 1H IN A 192.168.24.11
;; AUTHORITY SECTION:
mammals.org. 1H IN NS ns.exodus.net.
mammals.org. 1H IN NS fox.mammals.org.
;; ADDITIONAL SECTION:
ns.exodus.net. 15M IN A 206.79.230.10
fox.mammals.org. 1H IN A 192.168.24.5
The first three lines and the last four lines contain information that dig provides in addi-
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
IDENTIFIER
QR OPCODE AA TC RD RA Z AD CD RCODE
QDCOUNT
ANCOUNT
NSCOUNT
ARCOUNT
IDENTIFIER The first word of the header is a 16-bit identifier generated by the server
that issued the query. This identifier is used in the response so that the response can easily
be matched to the query.
The DNS software that Linux provides has an option called use-id-pool that improves
the randomness of the query identifier to avoid duplicates. While not required for basic
server operation, the use-id-pool option illustrates the scope of control you have over
the DNS configuration and demonstrates that you cannot fully understand the configu-
ration options available to you without understanding the underlying details of DNS. See
QR QR stands for query/response. This is a one-bit field that indicates whether the mes-
sage is a query or a response. 0 means it is a query and 1 means it is a response.
OPCODE The OPCODE is a four-bit field that defines what kind of query is contained
in the message. Like the identifier, it is initially set by the server that generates the query
and is left unchanged by the server that generates the response. There are five defined
OPCODE values:
0 means that this is a standard query. All queries for DNS database information
use this OPCODE.
1 means that this is an inverse query. Inverse queries are obsolete and no longer
used.
2 means that this is a query for server status, not a query for database informa-
tion. While defined, this OPCODE is not supported or used.
4 means that this is a DNS NOTIFY message. NOTIFY is a technique used to
synchronize the databases on master and slave servers.
5 means that this is an update message. Update messages change the records
stored in the DNS database on authoritative servers that support dynamic DNS.
AA AA stands for authoritative answer. This is a one-bit field that is used only when the
message is a response. The bit is set to 1 if the response comes from an authoritative
server. As explained in Chapter 1, all servers cache answers and can then answer queries
from their caches. These answers are not authoritative. Only a server responding to a
query for information in its zone of authority can provide an authoritative answer. When
an authoritative server provides an authoritative answer, it sets this bit to 1. When a
server answers from its cache of answers, it sets this bit to 0, indicating it is a non-author-
itative answer. You will create the authoritative servers for your domain.
TC TC stands for truncation. The truncation bit is set to 1 if the response was too large
to fit in a message and had to be truncated. If the truncation bit is 0, the entire response
fits into one message, which is the normal case.
RD RD stands for recursion desired. This bit is set to 1 to request recursion. Most clients
request recursion. RES_RECURSE, an option described in Chapter 4, “Configuring the
Resolver,” that causes the client to set this bit to 1, is compiled into the DNS software by
default. By its very nature, recursion means that the first recursive server to handle the
request will send out as many additional queries as are needed to find the answer to the
original question. Because the server is already recursively handling the query, it does not
need other servers to also recursively pursue an answer. The server normally sets this bit
to 0 on subsequent queries so that the other servers don’t unnecessarily start their own
RA RA stands for recursion available. This bit is set to 1 if the name server generating the
message supports recursion. It is set to 0 if the name server is a non-recursive server. By
default, Linux name servers are recursive servers. However, you control this through the
recursion configuration option covered in Chapter 8, “Special BIND Configurations.” PART 1
AD AD stands for authenticated data. This bit is set to 1 when the data in the message
has been authenticated using the DNS security (DNSSEC) protocol.
CD CD stands for checking disabled. Setting this bit to 1 indicates that the server is
unable to authenticate the message, not because the data failed authentication, but
because the server either does not have or has currently disabled support for the DNSSEC
protocols. See Chapter 10, “DNS Security,” for more information on DNSSEC.
RCODE The response code is a four-bit value used for error codes in a response message.
Linux software supports ten error codes:
0 No errors occurred. The response is good.
1 There was an error in the format of the query and the name server could not
understand the query.
2 Due to a name server failure, the name server was not able to process the
query.
3 The domain name referenced in the query does not exist. This is a very useful
error code when it comes from an authoritative server. It literally means that
the requested domain name does not exist, which is information that is just as
important as knowing the address of a domain name. For this reason, this
type of information is cached just like an answer containing an address. In
fact, this error code is referred to NXDOMAIN (non-existent domain) almost
as if it were a real DNS database record. Caching NXDOMAIN information
is called negative caching. Several times in the discussion of name server con-
figuration, we will examine options relating to negative caching.
5 The request was refused. The server supports the requested function but it
won’t do it for the client. Security is the primary reason for this response code.
You control what DNS services are offered and what hosts they are offered to
with configuration options like allow-query and allow-transfer.
6 The request contained a dynamic DNS update that attempted to add a domain
name that already exists. The update was rejected.
QDCOUNT QDCOUNT stands for query data count. This field contains the number of
entries in the question section of the message.
ANCOUNT ANCOUNT stands for answer count. This field contains the number of
DNS database records contained in the answer section of the message.
NSCOUNT NSCOUNT stands for name server count. This field contains the number of
DNS name server database records contained in the authority section of the message.
ARCOUNT ARCOUNT stands for additional record count. This field contains the
number of DNS database records contained in the additional section of the message.
dig does not display the header data in the order in which it occurs in the header section,
but it is still easy to identify:
opcode: QUERY clearly indicates that this is a standard query; in other words,
the OPCODE field contains a 0.
status: NOERROR is a little trickier. status really refers to the RCODE field
and NOERROR means that the RCODE field contains a 0.
id: 4 indicates that the identifier used for this message was the number 4. This
value doesn’t seem random. If your server generated this response, you might
want to enable the use-pool-id option described in Appendix B. It improves the
randomness of the identifier at the cost of a small increase in the memory used by
the name server.
flags: qr aa rd ra really covers four different fields in the header section and
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Query Name
Query Type
Query Class
query class used for all of your queries will be Internet, which is abbreviated as IN and has
Using information from the header, you know that this query section contains only one
query. The three fields of this query are clearly shown. You know the query is asking for
information about dog.mammals.org because that is the query name. Specifically, the
query is asking for the Internet address of dog. You know that because the query type is A,
which is the record type of address records, and the class field is IN, stating that the client
is only interested in Internet records. An Internet address query is the most common query
and it is the one that dig defaults to if no arguments are added to the dig command line.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
NAME
TYPE
CLASS
TTL
LENGTH
DATA
As you’ll see in Chapter 6, “Creating a Master Server,” most of these fields are entered
by you when you create the domain database for the master server. Although not entered
in exactly this order, the meaning of the fields will become very familiar to you as you
build your own database files. The fields are as follows:
NAME This is the domain name of the object to which this record relates.
TYPE This is the database record type. It can be any of the record types listed
in Appendix C.
CLASS This is the class of the database. It can be IN for Internet, HS for Hesiod,
or CH for Chaosnet. It is usually IN.
TTL This is the time-to-live field. It defines how long the database record can
be saved in a remote server’s cache.
LENGTH This is the only field that is not created by the domain administrator.
It specifies the length of the following data field in bytes.
DATA This is the data field that relates to this type of resource record. For
example, in an address record, this would be an address. On a name server record,
this would be the domain name of the name server. The data field varies in con-
tent and length depending on the record type.
Evaluating the dig Data for the Answer, Authority, and Additional Sections
The dig command in Listing 2.1 displayed the following answer, authority, and addi-
tional sections:
;; ANSWER SECTION:
dog.mammals.org. 1H IN A 192.168.24.11
;; AUTHORITY SECTION:
mammals.org. 1H IN NS ns.exodus.net.
mammals.org. 1H IN NS fox.mammals.org.
;; ADDITIONAL SECTION:
ns.exodus.net. 15M IN A 206.79.230.10
fox.mammals.org. 1H IN A 192.168.24.5
The header section displayed by dig says that there is one database record in the answer
section, two records in the authority section, and two records in the additional section.
The query asked for the address of dog and that is exactly what the answer section pro-
vides. dig displays the information in the order in which it is entered when building a
database record, which is slightly different from the order in which it is transmitted in a
response message. The answer shows the full domain name of dog. It shows that the TTL
for this record is 1 hour (1h). The class is IN for Internet, the type is A for address, and
Synchronizing Databases
Synchronizing databases begins with the exchange of request and response packets over
UDP just like any other DNS interaction. The request message sent depends on the tech-
nique being used to update the backup domain files. There are two techniques:
■ A traditional pull technique in which the backup servers pulls the data down from
the master server.
■ A newer push technique in which the master server pushes database updates out
to the backup servers.
that serial number to the serial number of its copy of the zone. If the serial number of the
master file is greater than the serial number of the slave’s copy of the zone, the slave
assumes that it needs to download an updated database from the master.
The slave server can download the entire database with a zone file transfer (AXFR) or it
can request just the changes to the zone with an incremental zone file transfer (IXFR). For
a full zone file transfer, the question section of the slave’s request message contains the
name of the domain being transferred in the query name field, IN in the Query Class field,
and AXFR in the Query Type field. The question section and a properly formatted header
section are all that is required for a zone file transfer request.
The request message for an incremental zone file transfer is slightly more complex. As you
might expect, the message contains a properly formatted header and a question section
that contains the name of the requested domain, the class IN, and the type IXFR. In addi-
tion, an incremental zone transfer request contains the slave’s SOA record in the authority
section. The slave sends its SOA record to the master so that the master knows how far
out of synchronization the database files are. The master then sends the slave those
records that have changed between the version of the zone the slave has and the current
version of the zone on the master. Unlike the AXFR, which transfers the entire file, only
the individual database records that have changed are sent in an IXFR.
The incremental zone transfer has the potential to greatly improve zone transfer effi-
ciency. But like many things that look good, it is not as easy as it sounds. IXFR reduces
network load at the cost of increased processing.
First, IXFR forces the master server to maintain a history of database updates in order to
know what should be sent to the slave. This history may need to be several changes deep,
depending on the frequency with which the zone changes and the slave checks for
changes.
Second, the slave needs to understand how to process these changes in a manner that guar-
antees that the database files are synchronized. These requirements increase the complexity
of the DNS software. Some DNS servers avoid the complexity by treating an IXFR as an
AFXR. In the long run, however, I expect that all name servers will comply with the RFCs
and support incremental zone transfer requests. Linux DNS servers do support IXFR.
back to the master. This is fine because the master server isn’t really interested in the
In Sum
The Domain Name System is a network-based, distributed database service. DNS uses
standardized protocols to communicate over the network. The network that DNS is built
on is the Internet. The Internet is a logical network created by the IP suite, which is com-
posed of IP, the transport protocols UDP and TCP, and application protocols. The DNS
network protocol is one of the application protocols. DNS works by exchanging stan-
dardized request and response messages over the network.
The DNS protocols are implemented in the Berkeley Internet Name Domain (BIND) soft-
ware. Every Linux name server uses BIND to construct the request and response messages
and perform all of the tasks associated with DNS. Chapter 3, “The BIND Software,”
introduces the BIND client/server software and describes how it is installed in your Linux
DNS server.