How exactly does recursive DNS work recursively? What are its underlying principles?
To understand recursive DNS, we first need to understand who's in the DNS "system." Imagine you want to find someone who lives in Beijing, but you only know their name, not their address. What would you do? You might first ask the neighborhood committee, if they don't know, they'd ask the street office, if they don't know, they'd ask the district, if the district asks the city… and so on, layer by layer, until you find the answer.
The DNS system works on this logic. It consists of four roles:
1. Recursive Resolver – This is what we call "recursive DNS." It's your agent, running errands for you. You give it the domain name, and it's responsible for getting to the bottom of things and then delivering the final answer. The vast majority of DNS used by ordinary users is recursive DNS. The addresses you set in your phone, like 114.114.114.114 and 8.8.8.8, are recursive DNS.
2. Root Name Server – The "central office" of the DNS world. It doesn't know the IP address of any specific domain name, but it knows where the authoritative DNS for all top-level domains (such as .com and .cn) is located. 3. Top-Level Domain Name Server (TLD) – Responsible for a specific domain suffix's "branch." For example, the TLD server for .com knows where the authoritative DNS for all .com domains is located.
4. Authoritative Name Server (DNS) – The "actual party" that ultimately answers the question. It is the true owner of the domain name; only it can tell you the actual IP address of baidu.com.
These four roles work in a hierarchical manner, forming a query chain from the "headquarters" to the "actual party." Recursive DNS is the one that completes this chain for you.
How exactly does recursion work? A complete addressing journey
Let's follow the recursive DNS through a complete query process, and you'll understand what "recursion" means.
Suppose you visit www.baidu.com for the first time, and your local cache is empty. Your computer sends a request to the recursive DNS (e.g., 114.114.114.114): "What is the IP address of www.baidu.com?"
After receiving the request, the recursive DNS begins its "errand-running" journey:
First stop: Root Name Server
The recursive DNS asks the root: "Where is www.baidu.com?" The root server says: "I don't know, but .com is managed by that TLD server, and this is its address."
Second stop: Top-Level Domain Server
The recursive DNS finds the TLD server for .com and asks: "b..." "Where is aidu.com?" The TLD server says, "The authoritative DNS for baidu.com is ns.baidu.com, and this is its IP address."
Third stop: Authoritative DNS server
The recursive DNS finds ns.baidu.com and asks, "What is the IP address of www.baidu.com?" The authoritative DNS checks its own record and says, "The IP address of www.baidu.com is 110.242.68.66."
Fourth stop: Home
The recursive DNS gets the answer and returns it to your computer. At the same time, it caches this record so that the next time someone asks for www.baidu.com, it doesn't need to make another trip.
Throughout the process, the recursive DNS queries three different servers and finally brings the answer back to you. This is "recursion"—it completes the entire query process from root to authoritative for you; you only need to ask once, and it gives you the final answer.
The opposite is "iterative query." In iterative mode, the root server doesn't query the TLD for you; instead, it tells you to "query the TLD," then you query the TLD yourself, the TLD tells you to "query the authoritative DNS," and you query the authoritative DNS yourself. You run the whole process yourself, querying several times before getting an answer. Recursive DNS is called "recursive" because it encapsulates this series of iterations, providing only a "one request, one response" interface to the outside world.
The "secret weapon" of recursive DNS: caching is its lifeblood.
Without caching, recursive DNS would have to run the entire process from root → TLD → authoritative DNS for every request. With billions of internet users worldwide and hundreds of billions of queries daily, it simply couldn't handle that.
Caching is the lifeblood of recursive DNS.
At which layers is the cache located?
Recursive DNS itself has a memory cache. After you query www.baidu.com, it stores the result for a period of time (determined by the TTL value specified by the authoritative DNS, usually from a few minutes to a few hours).
Your operating system also has a cache. After the recursive DNS returns the answer, the operating system caches it again.
Browsers also have their own DNS cache. You can see this by typing chrome://net-internals/#dns in Chrome.
These three layers of caching form a "caching pyramid." The higher up (closer to the user), the smaller the capacity and the faster the speed; the lower down, the larger the capacity, but relatively slower. A browser cache hit is the fastest; an operating system cache hit is next; a recursive DNS cache hit is next; only when none are hit is a full query performed.
TTL is a double-edged sword.
TTL is what the authoritative DNS tells the recursive DNS: "How many seconds can you cache this result?"
If the TTL is too short, such as 60 seconds, the recursive DNS will frequently expire, requiring a new query each time, putting pressure on the authoritative DNS and causing long waiting times for users.
If the TTL is too long, such as 24 hours, if you change the server IP, users will have to wait a day to access the new IP.
Experienced system administrators will find a balance between the two. For core domains (like the main website), set a shorter TTL (300-600 seconds) for quick switching; for static resource domains (like CDN), set a longer TTL (3600 seconds or more) to reduce pressure on authoritative DNS.
**Advanced Uses of Recursive DNS: It Can Do Much More Than Just Resolution**
Many people think recursive DNS is just a "domain translator," but it's much more than that.
1. Intelligent Traffic Splitting
Some recursive DNS systems can return different results based on the source IP. For example, if you're in Beijing, it resolves www.example.com to an IP address in a Beijing data center; if you're in Shanghai, it resolves it to an IP address in a Shanghai data center. This is the foundation of "intelligent DNS," and many CDN providers use this principle.
2. Malicious Domain Blocking
Enterprise-grade recursive DNS systems have a built-in blacklist of malicious domains. When users access phishing websites or mining pool domains, the recursive DNS directly returns a warning page instead of the actual IP address. This DNS-level security is more efficient than installing antivirus software on the terminal because it blocks malicious traffic at the first line of defense. 3. Content Filtering
Many parental control functions on home routers are implemented using recursive DNS. Setting up a filtering recursive DNS means that when a child tries to access adult websites, the DNS will directly return "Inaccessible".
4. Traffic Scheduling
Large internet companies often build their own recursive DNS clusters specifically for resolving their own domain names. This allows for precise control over traffic scheduling (e.g., returning the nearest data center based on the user's IP address) and avoids the instability associated with relying on third-party recursive DNS.
The Pitfalls of Recursive DNS: You Think It Helps You, But It Might Be a Problem
Recursive DNS is not a panacea; there are some pitfalls you may not have noticed.
Pitfall 1: Cache Poisoning
As mentioned earlier, caching is crucial, but it can also cause problems. For example, if a domain's authoritative DNS fails and returns an error response, the recursive DNS might cache that error response. Once the authoritative DNS recovers, the user still has to wait for the TTL to expire before they can access the site normally. This is "cache pollution".
Pitfall 2: Load Balancing Failure
Many large websites use DNS for load balancing, with one domain name corresponding to multiple IPs, and each resolution returning a different IP. However, if the recursive DNS's caching is too "aggressive," caching a certain IP for a long time, load balancing will fail, and all traffic will be routed to a single server.
Pitfall 3: TTL Disrespect
Some recursive DNS servers do not respect the TTL returned by the authoritative DNS, forcibly overriding it with their own policies. Where the authoritative DNS says "cache for 300 seconds," the recursive DNS says "I'll cache for 3600 seconds." The advantage is faster resolution, the disadvantage is that if the domain name changes its IP, it won't take effect for the user for an hour.
Pitfall 4: Privacy Risks of EDNS Client Subnet
To improve CDN scheduling, some recursive DNS servers include the user's IP range (EDNS Client Subnet) in the request, letting the authoritative DNS know the user's approximate location, thus returning the nearest IP. But this also means that the authoritative DNS can see the user's geographical location information, further compromising privacy.
What is the principle behind recursive DNS? It's actually not that complicated. It's essentially an agent who runs errands for users, asking from the root to the TLD, from the TLD to the authority, getting the answer and bringing it back to you, while also caching a copy so you don't have to go through that trouble again next time. But this seemingly simple role underpins the entire internet's "addressing system." Without recursive DNS, you can't remember those strings of IP addresses; without recursive DNS, CDNs don't know how to route traffic to the nearest node; without recursive DNS, a significant portion of the first line of defense for enterprise network security is missing.
CN
EN