Sub topic 2
Resource Records and TTLs
Assume you are comfortable with IP addresses, DNS queries, and editing a Linux configuration file. This chapter focuses on how DNS data is stored and how long resolvers keep that data.
A DNS resource record is one fact about a name. A record contains an owner name, a class, a type, a time to live (TTL), and type-specific data. The class is usually IN, meaning Internet.
Common resource records
| Type | Purpose | Example data |
|---|---|---|
| `A` | Maps a name to an IPv4 address | `192.0.2.20` |
| `AAAA` | Maps a name to an IPv6 address | `2001:db8::20` |
| `CNAME` | Makes one name an alias of another name | `web.example.com.` |
| `MX` | Identifies mail servers and their priorities | `10 mail.example.com.` |
| `NS` | Identifies authoritative name servers | `ns1.example.com.` |
| `SOA` | Describes a zone and its timing values | Zone metadata |
| `PTR` | Maps an address to a name for reverse DNS | `host.example.com.` |
| `TXT` | Stores text, often for verification or email policy | `"v=spf1 ..."` |
A name can have several records. For example, www.example.com. can have both A and AAAA records. An MX record must point to a hostname, not directly to an IP address. A CNAME usually cannot coexist with other data at the same owner name.
Names ending with a period are fully qualified domain names (FQDNs). The final period represents the DNS root. In a zone file, leaving it out can cause the server to append the zone name unexpectedly.
TTL and caching
The TTL is measured in seconds. It tells a caching resolver how long it may reuse an answer before asking an authoritative server again.
$TTL 3600
www IN A 192.0.2.20
mail IN A 192.0.2.25
@ IN MX 10 mail.example.com.Here, the default TTL is one hour. A record can override it by placing a value before the class:
api 300 IN A 192.0.2.30A short TTL lets changes spread sooner but increases query traffic. A long TTL reduces traffic and improves cache performance, but stale answers remain available longer after a change. Lower the TTL before a planned migration, wait for the old value to expire, make the change, and raise the TTL afterward.
How records guide a lookup
Inspect both the record and its TTL with dig:
dig @192.0.2.10 www.example.com A
dig @192.0.2.10 www.example.com A +noall +answer
dig @192.0.2.10 example.com SOA +shortThe number shown beside an answer is the remaining TTL, not necessarily the original value.
Exercise
You change an A record from 192.0.2.20 to 192.0.2.30, but clients still receive the old address. What is the first thing to check?
Show answer
Check the cached record's remaining TTL and wait for it to expire, or query the authoritative server directly to separate authoritative data from cached data.