CMD Guide
HomeSystem DesignDNS

Introduction to DNS

What is DNS (Domain Name System)?

DNS, or Domain Name System, is a system used to translate human-readable domain names (e.g., www.designgurus.com) into IP addresses (e.g., 198.47.25.1) that computers can understand. This translation process is crucial because computers and networking devices rely on IP addresses to identify and communicate with each other on the internet. In simple terms, DNS acts like a phonebook for the internet, allowing users to access websites using easy-to-remember domain names instead of having to memorize numeric IP addresses.

Purpose and Importance of DNS

The primary purpose of DNS is to make it easier for people to access websites and other online resources. By providing a human-readable naming system for computers and other devices connected to the internet, DNS enables users to navigate the internet using familiar and intuitive domain names.

DNS is essential for the smooth functioning of the internet. Some of its key benefits include:

DNS Components and Terminology

1. Domain names, TLDs (Top-Level Domains), and subdomains

2. DNS servers: Root, TLD, and Authoritative Name Servers

DNS
DNS

3. DNS resolvers

A DNS resolver is any component (software or hardware) responsible for translating a human-friendly domain name (like example.com) into the IP address that the computer needs to connect to (such as 93.184.216.34).

When you type a website address into your browser or click a link, your system relies on DNS resolvers to figure out the correct IP address. There are several types of DNS resolvers, each serving different roles in the DNS lookup process.

The DNS Lookup Process in Brief

In one line: your device’s stub resolver asks a recursive resolver (often your ISP’s or a public DNS like Google’s 8.8.8.8), which answers from its cache when it can and otherwise walks the hierarchy — root, then TLD, then authoritative — on your behalf. The full step-by-step walk, with round-trip counts and who recurses at each hop, is traced in "A concrete walk" further down this page.

1. Stub Resolver

A stub resolver is the minimal DNS client software running on your device (laptop, smartphone, IoT gadget, etc.) that starts the DNS lookup process. It typically does not perform the full DNS query process by itself.

How It Works

Example

2. Recursive Resolver

A recursive resolver is a DNS server that actively performs the DNS query process on behalf of the client. It hunts down the IP address by querying multiple DNS servers until it gets the final answer.

How It Works

  1. The recursive resolver receives a request from a stub resolver (or another forwarder).
  2. It first checks its local cache to see if the requested domain’s IP address is stored there.
    • If found, it returns the cached answer immediately.
  3. If the record is not cached, the resolver queries the root DNS servers to learn which TLD server (e.g., .com, .org) to query next.
  4. It then queries the relevant TLD server to find the authoritative DNS server for the specific domain.
  5. Finally, it queries the authoritative server to obtain the required DNS records (e.g., the A record for IPv4).
  6. The resolved IP is cached for future requests and returned to the stub resolver.

Example

3. Caching-Only Resolver

A caching-only resolver is a type of DNS server whose primary function is to cache DNS query results and reuse them to speed up subsequent lookups. It does not host any DNS zones (i.e., it is not authoritative for any domain) and typically performs recursive lookups on behalf of clients.

How It Works

Example

4. Forwarder

A forwarder is a DNS server that forwards all queries (or queries that it cannot resolve locally) to another DNS server instead of performing the complete recursive resolution process itself.

How It Works

Example

5. Iterative (Non-Recursive) Resolver

Sometimes called a non-recursive resolver, an iterative resolver typically gives back partial results or referrals, instructing the client to continue the resolution process on its own.

How It Works

This type is less common for end-user devices; it is often used by authoritative DNS servers to direct queries up or down the DNS hierarchy.

Example

Visualizing the DNS Resolution Chain

Below is a simplified chart showing the typical path of a DNS query:

User's Device (Stub Resolver)
     |
     v
Recursive Resolver (Often ISP/ Public)
     |
     v
  Root Server
     |
     v
 TLD Server (.com, .net, etc.)
     |
     v
 Authoritative Server (example.com)
     |
     v
   IP Address

Putting It All Together

  1. Stub Resolver on your device:

    • Minimal functionality—just sends the query to a DNS server.
  2. Recursive Resolver (may also be a Caching-Only Resolver):

    • Receives queries from stub resolvers.
    • Looks up (recursively) the chain of DNS servers if not cached.
    • Caches the response for future requests.
  3. Forwarder:

    • A DNS server configured to pass queries on to another resolver rather than doing the full lookup.
    • Can also cache responses.
  4. Iterative (Non-Recursive) Resolver:

    • Responds with direct answers if known or references to other DNS servers (referrals), but doesn’t do recursion.

Real-World Example Scenario

  1. Your Laptop (Stub Resolver) is set to use 8.8.8.8 (Google DNS).
  2. You type www.example.com into your browser.
  3. The stub resolver on your laptop sends the DNS query to 8.8.8.8 (a Public Recursive Resolver).
  4. Google DNS checks its cache:
    • If www.example.com is cached, it returns the IP right away.
    • If not, it queries the root server, then .com TLD server, then the example.com authoritative server in turn.
  5. Once found, the IP address is cached in Google’s DNS servers and returned to your laptop’s stub resolver.
  6. Your laptop connects to the returned IP address, and the website loads.

Why DNS is a hierarchy — and why that matters

DNS is not hierarchical because someone drew a tree. Three forces push the design toward delegation:

These three properties are inseparable: delegation lets different people run different parts, bounded knowledge keeps each server small, and caching keeps the root servers from melting.

A concrete walk: resolving www.example.com on a cold cache

Here is the exact chain of messages, with round-trip counts and who does the recursion at each step:

  1. Stub resolver → recursive resolver (1 round trip): "A? www.example.com" (recursive query — the stub expects a final answer). The recursive resolver holds the query open while it does the work.
  2. Recursive resolver → root server (1 round trip): root returns a referral to the .com TLD servers (iterative — the server returns a referral, never recursing).
  3. Recursive resolver → .com TLD server (1 round trip): TLD returns a referral to the authoritative name servers for example.com (iterative — a referral again).
  4. Recursive resolver → authoritative server (1 round trip): the authoritative server returns the A record (e.g., 93.184.216.34) and a TTL (iterative — but this server holds the answer, so the referral chain ends here).
  5. Recursive resolver → stub resolver: the held-open query finally returns the answer; the stub and OS cache it for the TTL.

The recursive resolver hides the iteration from the client; the root and TLD servers never recurse — they only point the resolver to the next authority.

That is four network round trips on a fully cold cache. On a warm cache the same query is often answered in about a millisecond from the local resolver. Short TTLs let you change infrastructure quickly but multiply the load on authoritative servers; long TTLs reduce load but slow propagation.

What can go wrong — the operability view

Choosing a resolver

TypeWhat it doesWhen to use itTrade-off
Stub resolverRuns on the device; forwards the query to a configured recursive resolver.Every phone, laptop, and container by default.Does no real resolution work; depends on upstream.
Recursive resolverWalks the hierarchy (root → TLD → authoritative) and caches answers.ISPs, enterprises, public services (8.8.8.8, 1.1.1.1).Carries cache state; wrong data here poisons many clients.
ForwarderPasses queries upstream without doing the full walk itself.Corporate networks that want to log/filter DNS centrally.Extra hop; still depends on the upstream resolver.
Caching-only resolverRecurses on behalf of clients and caches results, but is not authoritative.Home routers and small offices.Speeds up repeat lookups, but cache can be stale.

DNS "load balancing": promise and limits

DNS can return multiple A records (round-robin) or different answers based on the resolver's location (GeoDNS/GSLB). What it cannot do is see server load, health, or per-connection state. DNS steering is therefore coarse, TTL-bound regional steering, not a replacement for a layer-4/layer-7 load balancer with health checks. Use DNS to pick a region; use a real load balancer inside the region to distribute individual requests.

DNS record-type table

RecordPurposeExample
AMaps a hostname to an IPv4 addressexample.com. 300 IN A 93.184.216.34
AAAAMaps a hostname to an IPv6 addressexample.com. 300 IN AAAA 2606:2800:220:1::248
CNAMEAlias from one name to anotherwww.example.com. 300 IN CNAME example.com.
MXMail exchange server for a domainexample.com. 300 IN MX 10 mail.example.com.
NSAuthoritative name server for the domainexample.com. 300 IN NS ns1.example.com.
TXTArbitrary text, often for SPF/DKIM/DMARCexample.com. 300 IN TXT "v=spf1 ..."
SOAAdministrative info about the zonePrimary NS, admin email, serial, refresh, retry, expire, minimum TTL
PTRReverse DNS: IP back to hostname34.216.184.93.in-addr.arpa. 300 IN PTR example.com.

TTL and cache behavior

The TTL (Time To Live) on a DNS record tells resolvers how long they may keep the answer before asking again. TTL is a trade-off:

When you change an A record, every resolver that already cached the old value continues serving it until the TTL expires. OS stub resolvers, browsers, and middleware caches may also keep their own copies, so real propagation is TTL plus whatever extra caching layers exist.

Interview traps

Interactive scenario

Play with the dns simulator and predict the outcome before each step.

🤖 Don't fully get this? Learn it with Claude

Stuck on Introduction to DNS? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **Introduction to DNS** (System Design) and want to truly understand it. Explain Introduction to DNS from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **Introduction to DNS** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **Introduction to DNS** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **Introduction to DNS** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes