DNS: Hierarchy, Resolution, Records, and Caching
DNS (Domain Name System)
People have names and identification numbers, but usually prefer memorable names. Imagine introducing yourself as “Hello, I am 132-67-9875.”
Hosts likewise have memorable hostnames such as www.google.com and www.facebook.com. An IPv4 address has four bytes ranging from 0 to 255, written in dotted decimal, such as 121.7.106.83. Routers use structured numeric addresses; DNS translates hostnames into addresses.
The simplest design resembles a telephone directory: one DNS server stores every mapping, and clients query it directly. That creates several problems:
-
Single point of failure: Failure of the central service disrupts name resolution across the Internet.
-
Traffic volume: One server must process every query.
-
A distant centralized database: One location cannot be near everyone; some queries cross much of the globe.
-
Maintenance: The large database needs frequent updates for new hosts.
A Distributed Hierarchy
DNS addresses scale by distributing many servers worldwide in a hierarchy:
-
Root DNS servers.
-
Top-level-domain (TLD) servers.
-
Authoritative DNS servers.
To find www.amazon.com, a resolver asks a root for the com TLD servers, asks a TLD server for amazon.com's authoritative servers, then asks an authority for the hostname's address.
An ISP can provide a local DNS server. It is not itself a strict level in the hierarchy: a host sends it a query and it acts as a resolver on the host's behalf, contacting hierarchy servers when needed.
Resolve a name with recursive queries
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
Resolve a name with iterative queries
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
DNS caching reduces delay and query traffic. Resolvers retain learned mappings, so every lookup need not revisit the roots. Mappings are not permanent: cached information is discarded or refreshed after its lifetime.
Record Types and Lifetimes
DNS stores more than addresses. A provides IPv4 addresses, AAAA provides IPv6 addresses, CNAME points an alias at a canonical name, and MX identifies a domain's mail exchangers and priorities. An MX value is a server name, not message content or necessarily an IP address; that server name can need another lookup.
TTL (Time To Live) governs cached record lifetime. This TTL is a duration, not an IP packet's hop budget: the abbreviation is shared, but the objects and units differ. Remaining lifetime decreases with time; authority updates do not normally notify every cache immediately.
KNOWLEDGE QUIZ
Compute remaining DNS lifetime
A record is stored at t=0 with TTL 60 s. Write Python to print the remaining lifetime and freshness at t=45 and t=60. Expected lines: 45 15 True and 60 0 False. If the authority changed its A record at t=10, explain why the old cached answer may still be used at t=45. Assume no proactive invalidation or stale-serving extension.