How Does DNS Work?
Learn how DNS works — resolvers, root, TLD and authoritative servers, recursive vs iterative queries, caching and TTL — with networking interview questions.
Expected Interview Answer
DNS (Domain Name System) is the internet’s phonebook: it translates human-readable domain names like example.com into the IP addresses machines use to connect, by having a resolver query a hierarchy of name servers — root, top-level-domain, and authoritative — until it finds the answer.
When you request a domain, your device asks a recursive resolver (often run by your ISP or a public provider). If the answer is not cached, the resolver performs iterative queries: it asks a root server, which points it to the TLD server for the suffix (like .com), which points it to the authoritative server for the domain, which returns the actual IP address. The resolver caches the result for a duration set by the record’s TTL and hands the IP back to your device. This split between recursive resolution (the resolver doing the work) and iterative referrals (each server pointing to the next) plus caching at every level is what keeps DNS both scalable and fast.
- Maps memorable names to changeable IP addresses
- Caching and TTLs reduce lookups and latency
- Hierarchy distributes load and delegation
- Enables load balancing and failover via records
AI Mentor Explanation
DNS is like finding a player’s dressing-room number when you only know their name: you ask the front desk (the resolver), which does not know but points you to the stadium directory, then to the team’s manager, who finally gives the exact room. Each authority knows only who to ask next until the specific one answers. The desk remembers the number for a while so the next fan asking gets it instantly — exactly how DNS delegates queries and then caches the result.
Step-by-Step Explanation
Step 1
Check caches
The device and recursive resolver check their caches before any query goes out.
Step 2
Ask the root
On a cache miss, the resolver asks a root server, which refers it to the correct TLD server.
Step 3
Ask TLD then authoritative
The TLD server (e.g. .com) refers to the domain’s authoritative server, which returns the IP.
Step 4
Cache by TTL
The resolver caches the record for its TTL and returns the IP to the device.
What Interviewer Expects
- DNS maps domain names to IP addresses
- Recursive resolver vs iterative referrals
- The root → TLD → authoritative hierarchy
- The role of caching and TTL
Common Mistakes
- Thinking one server holds every domain mapping
- Confusing recursive and iterative resolution
- Ignoring caching and TTL entirely
- Not knowing DNS mainly uses UDP (port 53)
Best Answer (HR Friendly)
“DNS is the internet’s phonebook — it turns a name like example.com into the numeric IP address computers actually use. When you visit a site, a resolver asks a chain of servers until it finds the address, then remembers it for a while so future visits are instant.”
Code Example
# Ask a resolver to resolve a name to an IP
dig example.com A +noall +answer
# example.com. 3600 IN A 93.184.216.34
# ^ TTL in seconds the answer may be cached
# Trace the full root -> TLD -> authoritative referral chain
dig example.com +traceFollow-up Questions
- What is the difference between recursive and iterative DNS queries?
- What common DNS record types exist (A, AAAA, CNAME, MX)?
- How does DNS caching and TTL affect propagation?
- Why does DNS primarily use UDP on port 53?
MCQ Practice
1. What does DNS primarily translate?
DNS resolves human-readable domain names into machine-usable IP addresses.
2. Which server does a resolver contact first on a cache miss?
A root server is queried first; it refers the resolver to the correct TLD server.
3. What controls how long a DNS record is cached?
The record’s TTL (time to live) sets how long resolvers may cache it.
Flash Cards
What is DNS? — The system that maps domain names to IP addresses via a server hierarchy.
Resolution order? — Cache → root → TLD → authoritative server, then cached by TTL.
Recursive vs iterative? — Resolver does the full work (recursive); each server just refers onward (iterative).
DNS port and protocol? — Port 53, mostly UDP (TCP for large responses/zone transfers).