Trace a hostname lookup and predict how long an old DNS answer may be reused.
Lesson goal
Follow a cold lookup from browser to authoritative nameserver, then explain what changes when the answer is cached.
Before you begin — UDP.
Moving a service to another IP address should leave its links usable. The Domain Name System (DNS) lets clients look up records for a name such as api.example.com. An address record tells the client where to connect. Routers then use IP to forward the packets.
Consider https://api.service.example.com:443/v1/users?sort=desc&limit=10#section-2. The hostname in this example is api.service.example.com. DNS can resolve that name to an address. The browser uses port 443 for the connection and sends the path and query to the HTTP server. The fragment #section-2 stays with the browser.
.com..com nameserver refers the resolver to the authoritative nameservers for example.com.api.example.com in this example. If it supplies an alias, the resolver follows that name to obtain the address.The browser asks one resolver for an answer. The resolver makes the individual queries and follows referrals. A resolver with a cached referral can start further along this path.
To inspect a lookup, run nslookup example.com or dig example.com A. In a dig answer row, look for the name, the remaining time in seconds, the record type, and its value. The addresses and times you see can vary. With dig +trace example.com the tool follows referrals itself, which shows a different path from asking a recursive resolver for a cached answer.
| Record | Question it answers |
|---|---|
A, AAAA | Which IPv4 or IPv6 address is associated with this name? |
CNAME | Which other name is this one an alias for? |
NS, SOA | Which nameservers serve the zone, and what are its administrative details? |
MX | Which hosts accept mail for the domain, and in what preference order? |
TXT, PTR | What text has the operator published, or what hostname is listed for a reverse address lookup? |
A zone is a part of the DNS namespace administered together. At its top name, called the apex, the zone needs NS and SOA records. A standard CNAME cannot coexist with those records, so an operator can make www.example.com an alias but cannot use a standard CNAME at the example.com zone apex.
Registering a name and serving its records are separate jobs. A registrant registers a domain through a registrar, the registry maintains registrations for its top-level domain, and authoritative nameservers publish the domain’s records.
An operator changes an A record from 192.0.2.10 to 192.0.2.20. A resolver fetched the old value at 10:00 with a time to live (TTL) of 300 seconds. At 10:02 it can still return the old address. Under normal caching, after 10:05 it needs fresh information to answer again.
A shorter TTL can reduce the period during which old answers are reused. It also sends more lookups upstream. Lowering the TTL at 10:02 cannot retroactively shorten the copy fetched at 10:00. A dynamic DNS service can publish an address change automatically, and existing caches still follow the lifetime of their copies.
Conventional DNS commonly uses UDP port 53. If a UDP response is truncated, the requester can retry over TCP port 53 to receive the full answer. A client can also use TCP from the start. DNS transport requirements
DNSSEC lets a validating resolver check the origin and integrity of signed records. DNS over HTTPS (DoH) and DNS over TLS (DoT) encrypt the channel between the client and its chosen resolver. The resolver still sees the query. DNSSEC introduction · DoH specification · DoT specification
One visitor reaches the new service address at 10:02. Another reaches the old address a minute later. How can both lookups succeed?
The visitors can use different caches. A fresh lookup can see the new record while another resolver can still serve a valid cached copy of the old one.