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/hosts on 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.1 from your router, or 1.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 .dev TLD server at [TLD IP]” (referral).

Step 6: TLD Name Server

  • Resolver asks the .dev TLD server: “Who handles piyushgarg.dev?”
  • TLD replies: “Ask the authoritative server ns1.googledomains.com at [Auth IP]” (referral).

Step 7: Authoritative Name Server

  • Resolver asks ns1.googledomains.com: “What is the IP for piyushgarg.dev?”
  • Authoritative server replies: “piyushgarg.dev has A record 1.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.4 on 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

OptimizationWhereEffect
Browser cacheBrowserEliminates query for repeat visits
OS cacheOperating systemShared across apps
Router cacheLocal networkShared across devices
Resolver cacheISP / Public resolverShared across thousands of users
AnycastRoot / TLD / Public resolversRoutes to nearest physical server

Query Tools

  • nslookup <domain> — basic DNS lookup
  • nslookup <domain> <server> — query specific resolver
  • dig <domain> — detailed DNS query (Linux/macOS)
  • dig +trace <domain> — show full resolution path

Source