Skip to main content
DNS Explained – Complete Beginner to Advanced Guide
CHAPTER 03 Beginner

Understanding How DNS Works

Updated: May 15, 2026
20 min read

# CHAPTER 3

Understanding How DNS Works

1. Introduction

Typing a URL and pressing enter feels instantaneous. The webpage loads in a fraction of a second. But behind the scenes, that single keystroke triggers a frantic, global interrogation spanning thousands of miles. Your computer must ask a series of specialized servers a highly specific sequence of questions to hunt down the IP address. In this chapter, we will open the hood of the DNS engine. We will map the step-by-step resolution process and establish the critical mechanical difference between the two types of questions asked during this journey: Recursive Queries and Iterative Queries.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Trace the high-level step-by-step DNS lookup flow.
  • Define the role of a DNS Resolver (Recursive Resolver).
  • Explain the exact difference between a Recursive Query and an Iterative Query.
  • Understand how DNS servers pass authority down the hierarchy.

3. Beginner-friendly Explanations

The Detective Analogy: Imagine you are looking for a rare book, and you ask your local librarian to find it.
  • Recursive Query (The Librarian's Job): You tell the librarian: *"Find this book for me. I am going to sit here and wait until you come back with the exact book or tell me it doesn't exist."* You placed the entire burden of the search on the librarian.
  • Iterative Query (The Librarian Searching): The librarian doesn't know where the book is. So, they call the National Archive. The Archive says, *"I don't have it, but you should call the University Library."* The librarian calls the University. The University says, *"I don't have it, but call the Rare Bookstore."* The librarian calls the Bookstore, finally finds the book, and brings it back to you.

In DNS, your computer is YOU. The local DNS server is the LIBRARIAN. The global internet servers are the Archives and Bookstores.

4. The Resolver Process

When your computer connects to Wi-Fi, the router automatically assigns it a DNS Resolver (usually a server owned by your Internet Service Provider, like Comcast, or a public one like Google's 8.8.8.8). The Resolver is the "Librarian." It is the workhorse of the DNS system. It does all the heavy lifting on your behalf.

5. Step-by-Step DNS Lookup Flow

Let's trace the exact conversation when you type wikipedia.org.
  1. 1. The Recursive Query (You -> Resolver):
Your computer asks the Resolver: *"What is the IP for wikipedia.org? Give me the final answer."* (Recursive).
  1. 2. The Iterative Query 1 (Resolver -> Root Server):
The Resolver doesn't know. It asks the massive global Root Server: *"Do you know the IP for wikipedia.org?"* The Root Server replies: *"No, but I see it ends in .org. Here is the IP address of the .org Manager Server. Go ask them."* (Iterative).
  1. 3. The Iterative Query 2 (Resolver -> TLD Server):
The Resolver asks the .org Manager Server: *"Do you know the IP for wikipedia.org?"* The .org server replies: *"No, but I know who owns wikipedia. Here is the IP of Wikipedia's personal server. Go ask them."* (Iterative).
  1. 4. The Iterative Query 3 (Resolver -> Authoritative Server):
The Resolver asks Wikipedia's personal server: *"What is your IP address?"* Wikipedia replies: *"It is 103.102.166.224."* (Iterative).
  1. 5. The Final Answer (Resolver -> You):
The Resolver happily turns back to your computer and hands you the final IP address. Your browser connects to the website.

6. Command Examples

You can watch this exact global interrogation happen in real-time using the dig command with the +trace flag (available natively on Mac/Linux, or via WSL on Windows).
bash
12345678
# Force the terminal to show you every single server it talks to in the chain
dig +trace wikipedia.org

# Output snippet:
# 1. It asks the Root Servers (a.root-servers.net)
# 2. It asks the TLD Servers (a0.org.afilias-nst.info)
# 3. It asks the Authoritative Server (ns0.wikimedia.org)
# 4. It returns the final IP address!

7. Diagrams/Visual Suggestions

*Visual Concept: The Funnel* Visualize the process as an upside-down tree.
  • At the very top (the root) is a dot (.).
  • The tree splits into branches: .com, .org, .net.
  • The .org branch splits into leaves: wikipedia.org, npr.org.
The Resolver starts at the top of the tree and works its way down the branches until it finds the specific leaf it is looking for.

8. Best Practices

  • Understanding Caching: The 5-step process outlined above is actually quite slow. It takes hundreds of milliseconds to travel the globe. To fix this, Resolvers use Caching. If User A asks for wikipedia.org, the Resolver does the 5-step global search. When User B asks for wikipedia.org five minutes later, the Resolver skips the search and instantly replies from its memory cache.

9. Common Mistakes

  • Confusing Recursive and Iterative: The most common interview mistake. Remember: A Recursive query says, "Do the work for me." An Iterative query says, "Give me your best guess, and I'll keep searching." Your laptop *only* sends Recursive queries. The DNS servers use Iterative queries amongst themselves.

10. Mini Project: Change Your Resolver

By default, your ISP (AT&T, Spectrum) acts as your Recursive Resolver. They often log your browsing history. Let's switch to a faster, private Resolver.
  1. 1. Open your computer's Wi-Fi/Network Settings.
  1. 2. Locate the "DNS" configuration section.
  1. 3. Change the DNS Server to 1.1.1.1 (Cloudflare) or 8.8.8.8 (Google).
  1. 4. Save the settings. You have just fired your ISP's librarian and hired a much faster, highly optimized global librarian to do your Recursive searches!

11. Practice Exercises

  1. 1. If the .com TLD Server crashes globally, can a user still access google.com if their local Resolver has the IP address cached?
  1. 2. Explain why a standard web browser (like Chrome) is not designed to execute Iterative queries across the internet itself.

12. MCQs with Answers

Question 1

What type of DNS query demands a complete, final answer from the server, essentially forcing the server to do the hunting on the client's behalf?

Question 2

When a DNS Resolver asks a Root Server for an IP address, and the Root Server replies with a referral to the .com server instead of the final IP, what type of query has occurred?

13. Interview Questions

  • Q: Explain the mechanical difference between a Recursive DNS query and an Iterative DNS query. Which one does a standard laptop perform?
  • Q: If you use the dig +trace command, you will see the resolver ask multiple different servers in sequence. Explain the hierarchy of servers it communicates with.

14. FAQs

Q: How does my computer know where the DNS Resolver is in the first place? A: When you connect to Wi-Fi, a protocol called DHCP automatically assigns your computer its local IP address AND tells it the IP address of the local DNS Resolver.

15. Summary

In Chapter 3, we mapped the mechanical engine of domain resolution. We established the vital role of the DNS Resolver as the tireless librarian acting on our behalf. By dissecting the difference between Recursive queries (demanding a final answer) and Iterative queries (accepting a referral to the next server), we traced the exact multi-step conversation required to navigate the internet. We learned that domain resolution is not a simple database lookup, but a highly choreographed global interrogation.

16. Next Chapter Recommendation

We mentioned Root Servers, TLD Servers, and Authoritative Servers. What exactly are these machines, and who controls them? Proceed to Chapter 4: DNS Architecture and Hierarchy.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·