DNS Resolution Flow
When you type a URL into your browser, a complex but highly optimized sequence of events unfolds to translate that human-readable name into a machine-routable IP address.
Two Types of Resolution
Recursive Resolution
The DNS resolver (e.g., your ISP’s resolver, Cloudflare 1.1.1.1) does the heavy lifting. It queries the full hierarchy on behalf of the client and returns the final IP.
Iterative Resolution
Each server in the hierarchy responds with the best answer it has — either the final IP or a referral to the next server. The resolver follows these referrals until it gets the answer.
In practice, most client devices use recursive resolvers that handle the iterative walking internally.
Step-by-Step: Resolving piyushgarg.dev
Step 1: Browser Checks Local Cache
- The browser maintains an in-memory cache of recently resolved domains.
- Hit: Uses cached IP; no network traffic.
- Miss: Proceeds to the OS.
Step 2: OS Checks System Cache and /etc/hosts
- The OS checks its DNS cache and the local hosts file (
/etc/hostson Linux/macOS). - Hit: Returns IP to browser.
- Miss: Sends query to the configured DNS resolver (from
/etc/resolv.conf).
Step 3: Local Router (Optional)
- Many home/office routers run a DNS forwarder (e.g., dnsmasq).
- Hit: Returns cached IP.
- Miss: Forwards to the upstream recursive resolver.
Step 4: Recursive Resolver
- The resolver (e.g.,
192.168.1.1from your router, or1.1.1.1) receives the query. - Cache hit: Returns IP immediately.
- Cache miss: Begins iterative walk down the DNS hierarchy.
Step 5: Root Name Server
- Resolver asks one of the 13 root name servers: “Who handles
.dev?” - Root replies: “Ask the
.devTLD server at[TLD IP]” (referral).
Step 6: TLD Name Server
- Resolver asks the
.devTLD server: “Who handlespiyushgarg.dev?” - TLD replies: “Ask the authoritative server
ns1.googledomains.comat[Auth IP]” (referral).
Step 7: Authoritative Name Server
- Resolver asks
ns1.googledomains.com: “What is the IP forpiyushgarg.dev?” - Authoritative server replies: “
piyushgarg.devhas A record1.2.3.4” (answer).
Step 8: Response Caching and Delivery
- The recursive resolver caches the answer for the TTL duration.
- It returns the IP to the client (browser).
- The browser opens a TCP connection to
1.2.3.4on port 443 (HTTPS).
Visual Summary
┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ ┌─────┐ ┌─────────────┐ ┌─────────┐
│ Browser │───→│ OS/Router│───→│ Resolver │───→│ Root Server │───→│ TLD │───→│ Authoritative│───→│ Browser │
│ Cache │ │ Cache │ │ Cache │ │ (referral) │ │(.dev)│ │ (answer) │ │ Connect│
└─────────┘ └─────────┘ └─────────┘ └─────────────┘ └─────┘ └─────────────┘ └─────────┘
miss miss miss
“First your request goes to one of these root name servers which is closest to you. Then it is routed to the TLD server. Then it goes to your authoritative name server. And on every level they are caching it.” — Day 30 CKA Video
Optimizations Along the Path
| Optimization | Where | Effect |
|---|---|---|
| Browser cache | Browser | Eliminates query for repeat visits |
| OS cache | Operating system | Shared across apps |
| Router cache | Local network | Shared across devices |
| Resolver cache | ISP / Public resolver | Shared across thousands of users |
| Anycast | Root / TLD / Public resolvers | Routes to nearest physical server |
Query Tools
nslookup <domain>— basic DNS lookupnslookup <domain> <server>— query specific resolverdig <domain>— detailed DNS query (Linux/macOS)dig +trace <domain>— show full resolution path