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's8.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 typewikipedia.org.
- 1. The Recursive Query (You -> Resolver):
- 2. The Iterative Query 1 (Resolver -> Root Server):
.org. Here is the IP address of the .org Manager Server. Go ask them."* (Iterative).
- 3. The Iterative Query 2 (Resolver -> TLD Server):
.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).
- 4. The Iterative Query 3 (Resolver -> Authoritative Server):
- 5. The Final Answer (Resolver -> You):
6. Command Examples
You can watch this exact global interrogation happen in real-time using thedig command with the +trace flag (available natively on Mac/Linux, or via WSL on Windows).
bash
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
.orgbranch splits into leaves:wikipedia.org,npr.org.
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 forwikipedia.orgfive 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. Open your computer's Wi-Fi/Network Settings.
- 2. Locate the "DNS" configuration section.
-
3.
Change the DNS Server to
1.1.1.1(Cloudflare) or8.8.8.8(Google).
- 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.
If the
.comTLD Server crashes globally, can a user still accessgoogle.comif their local Resolver has the IP address cached?
- 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 +tracecommand, you will see the resolver ask multiple different servers in sequence. Explain the hierarchy of servers it communicates with.