DNS resolution is an important link in the Internet, which is responsible for translating domain names into IP addresses that can be read directly by computers. DNS resolution can be divided into recursive resolution and iterative resolution according to different query objects. Next, the three parties will briefly introduce the flow of the two query methods and the differences between the two methods.

What is a recursive query?

Recursive parsing is the most common and default method of parsing. In this resolution mode, if the Local DNS server configured on the client cannot resolve the DNS server, the Local DNS server replaces the DNS client in all subsequent queries until the Local DNS server obtains the correct resolution result from the authoritative DNS server. The local DNS server then tells the DNS client the result of the query.

In the whole recursive query process, except the client initiates a query request to the local DNS server at the beginning, the DNS client performs iterative query centered on the local DNS server. The DNS client waits until the local DNS server sends back the final query result. In effect, the local domain name server assumes the role of intermediary agent in the whole query process.

The query process of recursive parsing is roughly as follows:

1. The client sends a DNS query request to the local DNS server.

2. After receiving the request, the local DNS server queries the local cache and returns the recorded value to the client. If no record is recorded, the local DNS server sends a request to the root DNS server.

3. After receiving the request, the root DNS server returns the top-level DNS server (such as.com and.cn) to the local DNS server based on the suffix in the domain name to be queried.

4. The local DNS server sends a query request to the corresponding TOP-LEVEL DNS server based on the return result.

5. After receiving a DNS query request, the top-level domain name server (TLD) queries its own cache. If there is a resolution record of the requested domain name, the TLD returns the resolution record to the local DNS server.

6. If the TOP-LEVEL DNS server does not record a value, it returns the server address corresponding to the secondary domain name to the local DNS server. The local DNS server sends a request to the secondary DNS server again, and so on, until the authoritative DNS server in the corresponding region returns a result to the local DNS server. Then the local DNS server returns the recorded value to the DNS client and caches the local query record. In this way, the local DNS server can directly return the record to the client when the user queries the TTL value again.

What is an iterative query?

From the above introduction, we can see that the recursive query is performed by the local domain name server instead of the client except for the initial query request initiated by the client. Iterative query means that all the query work is carried out by the client itself. In addition, the whole query path and steps are not much different from recursive query.

DNS iterative query flow chart

First, the client sends a request to the local DNS server. If the local DNS server does not have cache records, the client initiates an iterative query to the root DNS server, top-level DNS server, and secondary DNS server in sequence until the final query result is obtained.

Iterative parsing is used when one of the following conditions is met:

1. When querying the local DNS server, if the client does not apply for recursive query in the request packet, that is, the RD field in the DNS request packet is not set to 1.

2. The client applies for recursive query in the DNS request packet, but the configured local DNS server forbids recursive query. That is, the RA field in the header of the DNS reply packet is set to 0.