Q&A-1Trace a DNS lookup from application to authority.
Answer
The 90-second answer
A DNS lookup is a walk down a delegation tree, with a cache at every hop. I'd trace it as application → stub resolver → recursive resolver → root → TLD → authoritative, and name what each hop caches and what it can return instead of an answer.
Concretely, an app on Linux calling getaddrinfo("api.example.com", ...):
- glibc consults
/etc/nsswitch.conf(hosts: files dns), misses/etc/hosts, then reads/etc/resolv.conf. Withsearch corp.example.comand the defaultndots:1, a name containing at least one dot is tried as absolute first; a bareapiwould getapi.corp.example.comappended before that. - The stub sends one UDP query to the configured nameserver, say
127.0.0.53(systemd-resolved), port 53, RD=1, random 16-bit ID, EDNS0 OPT advertising a 1232-byte UDP payload (the DNS Flag Day 2020 figure). - If that resolver has the name cached, it answers immediately and the trace stops there. On a miss it recurses from the root hints: 13 root server addresses,
a.root-servers.net= 198.41.0.4.
Then the referral chain, which is the part interviewers actually want:
| # | Query to | Answer section | Authority / additional | Flags |
|---|---|---|---|---|
| 1 | 198.41.0.4 (root) | empty | com. NS a.gtld-servers.net + glue A | AA=0, referral |
| 2 | 192.5.6.30 (a.gtld-servers.net) | empty | example.com. NS ns1.example.com + glue | AA=0, referral |
| 3 | ns1.example.com (203.0.113.53) | api.example.com. A 203.0.113.10 | — | AA=1, TTL 300 |
(Addresses in 203.0.113.0/24 are documentation range, used here as the example zone.)
The root and TLD servers never answer for api.example.com; they only point at the next zone down, and the glue records exist so the resolver doesn't have to resolve the nameserver's own name first. Only the authoritative server sets AA=1. The resolver caches each record for its TTL, 300 s here, so a repeat lookup inside that window is one hop, not four. Negative answers are cached too, for the SOA MINIMUM (RFC 2308), which is why a typo can look "sticky" for minutes after you fix it.
What decides the path
- UDP vs TCP: UDP by default; if the response exceeds the advertised buffer the server sets TC=1 and the stub retries over TCP:53. DNSSEC-signed zones and large RRsets hit this often.
- Plain vs encrypted: DoT (853) and DoH (443) hide the query from the local network but remove the middlebox visibility and shared caching you get from a resolver on 53.
- TTL: 300 s gives fast failover but roughly 5–10× the query volume of 3600 s.
Failure modes to name
- NXDOMAIN means the name doesn't exist (authoritative, negatively cached). SERVFAIL means the resolver failed: DNSSEC bogus, timeout, or all upstreams down. Different bugs, different fixes.
- Truncation: TC=1 with no TCP retry shows up as intermittent failures on large answers.
- Stale TTL after a failover: the old A record keeps being served until it expires.
- Split-horizon: internal and external resolvers return different answers for the same name; check which resolver the client actually used before debugging the zone.
Curated: · Written: · Reviewed:
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.