Sub topic 10
The DNS hierarchy: root, TLD, and authoritative servers
This chapter assumes you know the layered network model, what a socket and a port are, and that UDP is a connectionless transport. It covers the structure of the Domain Name System (DNS) and the roles of the servers in it. The next chapter follows a query through this structure. The chapter after that covers record types and the message format.
Why DNS needs a hierarchy
Hosts are reached by IP address, but people use names such as www.example.com. DNS is a distributed database that maps names to values, mainly IP addresses. It runs at the application layer. Most queries use UDP port 53, and TCP port 53 is used when a response is too large or for zone transfers.
A single central server would fail for three reasons:
- Single point of failure. If it went down, no name could be resolved.
- Traffic volume. One server cannot handle every lookup on the Internet.
- Distance and maintenance. A central server is far from most clients, and one organization would have to update every name change.
DNS therefore splits the database across many servers arranged as a tree. No server holds every mapping.
The name tree
A domain name is read right to left, from the most general label to the most specific one. In www.cs.example.com. the final dot stands for the root, and the labels are:
comis the top-level domain (TLD).exampleis a second-level domain undercom.csis a subdomain underexample.com.wwwis a host name insidecs.example.com.
Each label is at most 63 characters, and a full name is at most 255 characters. Names are case-insensitive.
Three levels of servers
The server hierarchy follows the name tree, with three levels that matter for a lookup.
Root servers
The root servers know where to find the servers for every TLD. There are 13 root server addresses, named a.root-servers.net through m.root-servers.net. Each address is not one machine. Each is served by many physical machines in many locations using anycast, where the same IP address is announced from several places and a query reaches the nearest one. Counting these instances, there are well over a thousand root servers worldwide.
The root does not know the address of www.example.com. It only knows which servers handle com, and it replies with that referral.
TLD servers
TLD servers handle one top-level domain each. TLDs fall into two groups:
- Generic TLDs such as
com,org, andnet. - Country-code TLDs such as
in,uk, andde.
A TLD server knows which servers are authoritative for each second-level domain beneath it. The com TLD server does not know the address of www.example.com. It knows the name servers for example.com and replies with that referral.
Authoritative servers
An authoritative name server holds the actual records for a zone and gives answers that are the final word for it. An organization with publicly reachable hosts must provide authoritative servers for them. It can run them itself or pay a service provider. Organizations usually run at least two authoritative servers, a primary and a secondary, for redundancy. The secondary copies the zone from the primary through a zone transfer.
Summary of the three levels
| Level | Knows | Typical reply to a query for `www.example.com` |
|---|---|---|
| Root | Servers for each TLD | Names and addresses of the `com` servers |
| TLD | Servers for each domain under the TLD | Names and addresses of the `example.com` servers |
| Authoritative | Records of its own zone | The IP address of `www.example.com` |
Domains versus zones
A domain is a subtree of the name tree. A zone is the part of a domain that one set of authoritative servers manages directly. The two differ when management is delegated.
Suppose example.com has the subdomain cs.example.com. The owner can delegate cs to another server set. The example.com zone then holds a pair of records that points to the servers for cs, and those servers manage the cs.example.com zone. The domain example.com still contains cs.example.com, but the zones are separate.
Delegation is what makes the system scale. Each zone's administrators update only their own records, and nobody coordinates a global file.
Local DNS servers
One more kind of server sits outside the hierarchy: the local DNS server, also called the default name server, the recursive resolver, or the caching resolver. Each ISP, university, or company runs one. A host's configuration, from DHCP or set by hand, gives it the address of this server.
A host sends all its DNS queries to the local server. The local server does the work of contacting the root, TLD, and authoritative servers, then returns the final answer. It also caches what it learns, so it is often close to the host, in network terms, and can answer repeated queries quickly.
The local server is not part of the hierarchy. It does not hold authoritative data for other people's domains. Its role is to act on behalf of clients.
A short walk through the hierarchy
For www.example.com, the local server follows these steps when its cache is empty:
- It asks a root server, which refers it to the
comTLD servers. - It asks a
comserver, which refers it to theexample.comauthoritative servers. - It asks an
example.comserver, which returns the IP address.
The roots and TLD servers are only referrals here. This is why a root server never needs to know about individual hosts. The next chapter covers the iterative and recursive query styles in detail.
Looking at the hierarchy from code
You can inspect what the resolver returns for a name. This program asks the operating system's resolver for the addresses of a host. The operating system contacts the local DNS server for you.
import socket
host = "example.com"
seen = set()
for family, socktype, proto, canonname, sockaddr in socket.getaddrinfo(
host, 80, type=socket.SOCK_STREAM):
if sockaddr not in seen:
seen.add(sockaddr)
print(family.name, sockaddr)Typical output has an AF_INET line for an IPv4 address and often an AF_INET6 line for an IPv6 address. The program shows only the final answer. The root, TLD, and authoritative steps happen inside the local server and are invisible to it. To see them you need a tool such as dig +trace example.com, which performs the iterative walk itself, starting at the root.
Common errors and edge cases
- Thinking the root knows every host. The root knows only TLD servers. A question that says "the root server returns the IP address of the host" is wrong unless the host is itself in the root zone.
- Confusing the local server with the root. The local DNS server is not one of the 13 root names and is not authoritative for other domains.
- Counting root servers. There are 13 root server addresses (letters
atom), but many more physical machines. - Mixing up domain and zone. A zone can be smaller than a domain because of delegation.
- Assuming authoritative means "the first server asked". Authoritative describes who owns the data, not the order of contact.
- Forgetting that a hierarchy of names is not a hierarchy of network distance.
.inservers can sit anywhere. A name's position in the tree says nothing about where its servers are located.
GATE-style takeaways
- The number of lookups to the hierarchy depends on the cache. With an empty cache, a lookup of a host in a second-level domain such as
example.comneeds a root query, a TLD query, and an authoritative query. - If the local server already has the TLD server's address cached, the root is skipped.
- If the local server has the final answer cached, no other server is contacted.
- A host contacts only its local server. Whether the local server then asks others is its own business.
Exercise
A local DNS server with an empty cache resolves www.cs.example.com, and cs.example.com is a separately delegated zone. Which servers does it contact, in order, and what does each one return?
Show answer
It contacts four kinds of server, in this order. (1) A root server, which returns the addresses of the com TLD servers. (2) A com TLD server, which returns the addresses of the example.com authoritative servers. (3) An example.com authoritative server, which returns a referral to the cs.example.com servers, because that zone is delegated. (4) A cs.example.com authoritative server, which returns the IP address of www.cs.example.com. Delegation adds one extra step compared with a host that sits directly in example.com.
Exercise
State two reasons DNS uses a distributed hierarchy of servers instead of one central server, and name the type of server that gives the final mapping for a host.
Show answer
A central server would be a single point of failure and could not handle the query volume of the whole Internet. Maintenance would also be centralized, instead of being delegated to each domain's owner. The authoritative name server for the host's zone gives the final mapping.