Topic 026 / Core
DNS
Chapter 3.1 · Network Foundations
What and why
Humans and applications want to refer to a server by a stable name, but routing (→ 24) needs a numeric address, and that address can change over the server's lifetime. DNS (Domain Name System) is a distributed, hierarchical, cached lookup system that resolves names to addresses. Builds on: → 24.
Diagram
Text version of this diagram
stub resolver ──► recursive resolver ──► root server
(your OS) (checks cache first) │
▼
TLD server (.com)
│
▼
authoritative server (example.com)
│
▼
answer, cached for its TTL
How it works
- An application asks its stub resolver (part of the OS) to resolve a hostname.
- The stub resolver asks a recursive resolver, which first checks its own cache.
- On a cache miss, the recursive resolver queries a root server for the relevant top-level domain's name servers.
- It then queries a TLD server for the authoritative name servers of the specific domain.
- It queries the authoritative server for the actual record (commonly A/AAAA for an address, CNAME for an alias, TXT for arbitrary text).
- The recursive resolver caches the answer for its record's TTL and returns it to the stub resolver, which hands it to the application.
Practical example
(illustrative). The first lookup for a hostname walks the full chain above; a second lookup for the same name, while the TTL hasn't expired, is answered straight from the recursive resolver's cache — no root, TLD, or authoritative query at all.
When to use it
- Use when: any system with more than a trivial, fixed number of hosts, or one where addresses change over time — DNS decouples a stable name from a changeable address.
- Avoid when: hardcoding IP addresses in application code — it works until the infrastructure behind that address changes, and then it silently stops working.
- Failure scenarios: a DNS outage breaks every downstream lookup even if the servers behind the name are healthy; a record change takes up to its old TTL to be fully visible, because resolvers that already cached it keep answering with the stale address; relying on DNS alone for fast failover is slow precisely because of that caching.
- Simpler alternative: a hosts file (a static name-to-address mapping) for a handful of machines that never change — not viable once the set of hosts is dynamic.
Practice
(mechanism kind — trace by hand; 15 min, no lab services). Use dig against
a real domain. Record the record type returned, its TTL, and the answer. Run the same query
again immediately and note that the TTL you observe has counted down rather than reset —
that's the cache from step 6, not a fresh lookup. Done when you can name which resolver
answered each query and why the TTL counted down instead of resetting.
Key takeaway
DNS is a distributed, cached directory from name to address; its caching is also why it reacts slowly to change. Done when you can: trace a resolution chain by hand and explain why a DNS change doesn't take effect everywhere instantly. Used next in → 30 (the URL narrative), → 94 (DNS is also a load-balancing and failover tool).
References
None — this topic makes no external claims.
Exercise: With dig, traceroute, and curl -v, trace one real request: DNS
resolution, TCP connect, TLS handshake, HTTP exchange — and record each stage's latency.
(TLS and the HTTP exchange are explained next, in Chapter 3.2 — record their timings now;
the explanation comes there.)