Sub topic 4
Name servers and zones
This chapter assumes you know the root, TLD, and authoritative levels of the DNS hierarchy from the previous chapter. It also assumes you can run commands in a terminal. Here you learn which servers hold DNS data, how that data is divided into zones, and how to read a zone file.
Name servers
A name server is software that answers DNS queries. Two roles matter:
- An authoritative name server stores the records for one or more zones and gives definitive answers about them.
- A recursive resolver looks names up on behalf of clients. It stores no zones of its own. The next chapter covers it.
This chapter is about the authoritative role.
What a zone is
A zone is the part of the DNS namespace that one administrator manages as a single unit. It is stored as a set of records, usually in a zone file.
A zone is not the same thing as a domain. The domain example.com covers every name beneath it. The zone for example.com covers only the names that its owner has not delegated elsewhere. If the owner adds NS records that hand dev.example.com to other servers, dev.example.com becomes its own zone.
A delegation is a set of NS records in the parent zone. They point to the servers that are authoritative for the child zone.
Primary and secondary servers
A zone needs at least two name servers, so that it still resolves when one fails. They can be set up in two ways:
- The primary server holds the editable master copy of the zone.
- Secondary servers copy the zone from the primary by a zone transfer.
A secondary periodically reads the SOA record from the primary and compares serial numbers. If the primary's serial is higher, the secondary transfers the new data. Managed DNS providers hide this arrangement, but the same idea sits behind it.
Reading a zone file
This is the zone file for example.com, using reserved documentation addresses.
$ORIGIN example.com.
$TTL 3600
@ IN SOA ns1.example.com. hostmaster.example.com. (
2025010101 ; serial
7200 ; refresh
3600 ; retry
1209600 ; expire
3600 ) ; negative-caching TTL
@ IN NS ns1.example.com.
@ IN NS ns2.example.com.
@ IN A 192.0.2.10
@ IN AAAA 2001:db8::10
www IN CNAME example.com.
@ IN MX 10 mail.example.com.
mail IN A 192.0.2.25
@ IN TXT "v=spf1 mx -all"
ns1 IN A 192.0.2.53
ns2 IN A 192.0.2.54$ORIGINsets the name that@stands for. A name with no trailing dot, such aswww, has the origin appended.$TTLis the default cache lifetime in seconds.- The SOA (start of authority) record must appear once, at the top. It names the primary server and the administrator's mailbox, with the first
.standing in for@. It also holds the serial and the timers. refreshis how often a secondary checks the serial.retryis how long it waits after a failed check.expireis how long it keeps serving without reaching the primary.- The last SOA number is the negative-caching TTL, which is how long resolvers remember that a name does not exist.
- The NS records at the apex (
@) list the zone's own name servers. ns1andns2need address records. Their names sit inside the zone they serve, so the parent zone must also supply those addresses as glue records. The registration chapter covers that.
Asking an authoritative server directly
You can query a zone's server yourself. Without recursion, the server answers only from its own data.
dig example.com NS +short
dig example.com SOA +short
dig @a.iana-servers.net example.com A +norecurseIn the third command, look for the aa (authoritative answer) flag in the output header. Its presence shows the answer came from the zone's own data and not from a cache.
Common errors
- Stale serial. If you edit a zone and forget to raise the serial, secondaries do not copy the change. They then serve different answers. A date-based format such as
2025010101makes this easy to avoid. - Lame delegation. The parent lists a server that does not actually serve the zone. Some queries then fail or time out.
- Mismatched NS sets. The parent's NS records and the zone's own apex NS records disagree. Resolvers may behave inconsistently.
- Missing glue. The name servers live inside the zone they serve and the parent supplies no addresses for them. Resolvers cannot reach them.
Exercise
A secondary name server keeps returning an old IP address for your site, even though you edited the A record on the primary. What is the most likely cause, and how do you check it?
Show answer
The SOA serial was probably not increased, so the secondary never started a zone transfer. Run dig example.com SOA +short against each name server and compare the serial numbers. Raise the serial on the primary and confirm that the secondary's serial matches afterward.