In this article, we are going to discuss DNS Recursive Query and DNS Iterative Query and also the difference between them.
Let’s see what is the goal of the DNS?
The goal of the DNS is to resolve Fully Qualified Domain Name(FQDN) to an IP address. This process is called “Name Resolution”.
Now let’s have a brief introduction of DNS Recursive Query and the DNS Iterative Query.
The Recursive Query is between a DNS Client and its local DNS server. Recursive Query demands this Name Resolution or an answer which it cannot find.
On the other hand, the Iterative Query is between a Local Server and other DNS servers.
The iterative query does not demand a Name Resolution which means other DNS servers may provide a Name Resolution if they know or simply respond with a referral.
Now, let’s discuss this whole process of Name Resolution and also explain these two queries with an example:
Assume that you want to go to a hosttest web server, for that you will require to type www.hosttest.com in your web browser. When you press Enter, your web browser will check two places first to see if there is any previous Name Resolution record of this machine.
First place is your computers’ Cache memory i.e. it will check cached DNS records.
The second place is a simple text file called as “Hosts” i.e. it will check for Host file.
Now assume that there is no record in either of these two locations. Your computer would ask your local DNS server a question i.e. I want to know the IP address of www.hosttest.com?
This initial query from your computer which is a DNS client to your local server is called as “Recursive Query”. Because your computer demands a clear answer to resolve a name, is the responsibility of your local DNS server.
Now, let’s assume that your local DNS server is a brand new machine and it has no records of any IP address of www.hosttest.com. Then it would give a reply as: “I am sorry, I don’t know the IP address of hosttest but I will find it out for you.”
From here the Iterative Query starts:
Always remember that during an Iterative Query, other DNS servers can simply provide a referral if they do not know the requested IP address i.e., in this case, the IP address of www.hosttest.com.
Note that your local DNS server is looking for an IP address of a DNS server hosting web server, a specific host at the very bottom of the namespace pyramid specified by its Fully Qualified Domain Name(FQDN). i.e. here it is www.hosttest.com.
So, first, your local server will go up to a root Domain name server and asks:”Do you know what is the IP address of www.hosttest.com?” We know that root domain servers are only responsible for Top-level Domain servers such as .com, .net, .org etc.
Thus the root server would reply “I don’t know the IP address of www.hosttest.com but I do know an IP address of a .com server”.
Here the root domain server gives a referral. Then your local DNS server goes to .com domain server asking the exact same question: “What is the IP address of www.hosttest.com?”
The .com server gives reply:”I don’t know the IP address of hosttest web server but I do know the IP address of a hosttest DNS server”. Here .com server gives a referral.
The local server goes to hosttest DNS server and asks the same question:” What is the IP address of www.hosttest.com?” Well, this time the answer is “Yes”. as the DNS server of hosttest knows the hosttest.com IP address. Now his reply will be: ” Here is the IP address of www.hosttest.com which you can use”.
Once your local DNS server gets it’s IP address, it informs to your computer which you can use for talking with hosttest server.
Thus your local DNS server saves this IP address in its memory if next time when any other computer in the network asks the same question it would give this IP address directly from its memory without going through all those repetitive steps which we discussed above.
A DNS recursive query is between a DNS client which is your computer and it’s local DNS server. The local DNS server is responsible for answering the questions from DNS clients.
When this local DNS server could not resolve a new name from its own database, it would make an iterative query to other DNS servers until it finds the answer.