current position:Home>Detailed process of DNS recursive query and iterative query

Detailed process of DNS recursive query and iterative query

2022-02-03 16:17:39 JyLie

Noun analysis

-  domain name :`www.google.com`
-  The local name server configured by the client :`dns.google.com`
-  Domain name root directory name server `a.rootserver.net`

-  The main character 

  - DNS  Customer  -> `DNS  Customer `
  -  Local name server  -> `Local DNS`
  -  Root name server  ->`.`
  -  Class A ( top ) Name server  -> `com`
  -  Secondary name server  -> `google.com`
  -  Authoritative name server  -> `www.google.com`
 Copy code 

Basic knowledge of

DNS,Domain Name System/ The domain name system , An Internet oriented domain name and IP A distributed database with address mapping . It is a tree structured record 、 Mapping domain names and IP Address distributed system .DNS Query usage UDP agreement .

Why do you need DNS Well , Because the data interaction between terminals is through IP Address to locate the target ,IP Address: e.g 192.168.8.8. Because of man's irregular IP The address is not easy to remember , Therefore, we usually use Domain name address Instead of IP Address Search and use , But in fact, the access between terminals is finally through Domain name address mapping IP Address .

Users are used to using domain names and addresses to access terminals , When the browser makes a request , The operating system will use DNS To query the corresponding domain name address IP What's the address , After the query is successful, the operating system will pass IP Address to access the terminal to obtain resources .

domain name DNS Name server queries are from the root . According to the principle of right to left .

Usually , The query from the host to the local name server usually adopts iterative query , And the local name server sends to DNS( Class A 、 second level 、 Level three ...) The name server adopts recursive query .

The host DNS There are two main ways to query , recursive query and Iterative query , The main difference is :

  • send out DNS When inquiring ,DNS Request header Of RD Field Default by 1, The default is recursive query .

    • RD by 1 => recursive query , Default query method
    • RD by 0 => Iterative query
  • recursive query With Local name server Centered ,DNS The client only sends the original domain name query request message , And then I've been waiting , Until the local name server sends the final query result . At this point, the local name server is equivalent to Intermediary agent The role of .

  • recursive query The trigger condition of :1. Default trigger ;2. RD Set to 1 Trigger ;

  • Iterative query With DNS The client itself Centered . All inquiries are DNS The client does it by itself .DNS Customer In order towards Local name server 、 Primary name server 、 Secondary name server 、 The authoritative name server sends a query DNS Of Request query message , In this process, each level of server will return a list of the next name servers that can answer the query A, Get the information of the next query list A after DNS Customer Will return to the list of A Make a request in , Until you find the name server that is ultimately responsible for the domain name you are looking for , Get the final result from it .

  • Iterative query The trigger condition of :1. Query the trigger on the configured local name server ( Because the local name server prohibits recursive queries );2. RD Set to 0 Trigger ;

  • recursive query and Iterative query The steps of querying a primary domain name server to an authoritative domain name server are similar , The main difference is recursive query With Local name server Centered The query , Iterative query With DNS The client itself Centered Inquire about .

DNS Iterative query

Iterative query , Also called iterative parsing . When using iterative parsing , All inquiries are made by DNS The customer did it himself . If the primary name it is configured is called server ( Such as Windows In the system The preferred DNS The server ) If it can't be resolved , The client will also continue to configure other name servers ( Such as Windows In the system spare DNS The server ) Inquire about .

If we consider the caching technology of the local name server ( stay DNS Save a certain number of queried records on the server for a certain time , In this way, when querying the same domain name information, it can be directly transferred from the cache , To speed up query efficiency ) Words , The basic process of iterative name resolution is as follows ( Here only to first DNS Take server as a local name server as an example , With other standby DNS The parsing process of the server is exactly the same ):

  1. DNS client Configured to this machine Local name server issue DNS Domain name query request .

  2. Local name server Upon receipt of the request , First query the local cache , If there is a record entry for the domain name , Then the local name server will directly return the query results to the client ; If there is no record of the domain name in the local cache , to DNS The client returns a DNS Reply message , Some reference information will be given in the message , For example, the root name server address on the local name server .

  3. DNS client After receiving the response message from the local name server , According to the root name server address information , Issue the same as before to the corresponding root name server DNS Query request message .

  4. Root name server Upon receipt of DNS After querying the request message , By checking your own DNS The database is requested DNS The top-level name server information corresponding to the top-level domain name in the domain name , Then with a DNS The reply message is returned to DNS client .

  5. DNS client According to the address information of the corresponding top-level name server in the response message from the root name server , Issue the same... As before to the top-level name server DNS Query request message .

  6. Top level name server Upon receipt of DNS After the query request , First query your own cache , If there is a request DNS Domain name entries , Then directly return the corresponding record item to DNS client , Otherwise, the server address information of the secondary name corresponding to the secondary domain name in the corresponding domain name will be listed as one DNS The reply message is returned to DNS client .

  7. DNS client Continue to follow steps 5 And steps 6 The methods are divided into three levels 、 Four level name server query , Until the final authoritative name is found, the server returns to the final record .

If in the above steps, the authoritative name server of the corresponding domain name says that the corresponding domain name record cannot be found , Will go to DNS The client returns a query that fails DNS Reply message . Of course , If the authoritative name server is configured with forwarders pointing to other name servers , Then the authoritative name server will further repeat the above steps on the name server pointed to by the forwarder . in addition , If DNS More than one... Is configured on the client DNS The server , Will continue to other DNS The server queries .

DNS Once you find it here, you can basically get the corresponding... Of the domain name IP 了 , Unless the domain name to be searched is not configured IP The query fails .

DNS Iterative query - Example

For ease of understanding , Give a specific example , to glance at DNS The workflow of iterative parsing :

  • Suppose the client wants to visit a site that he doesn't recognize www.google.com, that DNS The query path of the customer service end is as follows :
  1. DNS client To the configured local name server dns.google.com Send resolution www.google.com Domain name DNS Request message .

  2. Local name server received Client's DNS After querying the request message , First query the local cache . Suppose no corresponding record of the domain name is found , Then the local name server takes the configured root name server a.rootserver.net Address information to DNS The reply message is returned to DNS client .

  3. DNS client After receiving from the local name server DNS After answering the message , According to the root name given in the server address information , Send the resolution to the corresponding root name server again www.google.com Domain name DNS Request message ).

  4. Root name server Upon receipt of DNS After the query request , Get... By querying .com The top-level name server corresponding to the top-level domain name , Then query the corresponding top-level domain information with a DNS The reply message is returned to DNS client .

  5. DNS client After receiving the from the root name server DNS Reply message , obtain .com After the top-level name server address corresponding to the top-level domain name , Send a resolution to the corresponding top-level name server again www.google.com Domain name DNS Request message .

  6. .com Top name server is receiving DNS Client's DNS After querying the request message , First query your own cache , Suppose there is no record item of the domain name , Then check google.com Corresponding secondary name server , Then query the corresponding secondary domain information with a DNS The reply message is returned to DNS client .

  7. DNS client Upon receipt of .com Top name server DNS Reply message , obtain google.com After the secondary name server address corresponding to the secondary domain name , Send a resolution to the corresponding secondary name server again www.google.com Domain name DNS Request message .

  8. google.com The secondary name server is receiving DNS Client's DNS After querying the request message , Also query your own cache first , Suppose there is no record item of the domain name , Then check www.google.com The corresponding authoritative name server ( Because this name server already includes the whole domain name www.google.com Area ), Then query the corresponding authoritative domain name information with a DNS The reply message is returned to DNS client .

  9. DNS client Upon receipt of google.com Secondary name server DNS Reply message , obtain www.google.com After the authoritative name server address corresponding to the third level domain name , To the corresponding... Again Authoritative name server Send resolution www.google.com Domain name DNS Request message .

  10. Authoritative name server ``www.google.com Upon receipt of DNS Client's DNS After querying the request message , In its DNS Look up... In the area database , Finally came to www.google.com The domain name corresponds to IP Address . And then to DNS The client returns a DNS Reply message . such DNS Client acquisition IP After the address, you can normally visit this website .

DNS recursive query

recursive query ( Recursive parsing ) yes Default Of DNS Analytical way . In this way of parsing , If the local name server configured by the client encounters a problem that cannot be resolved , Then the following queries are all by Local name server Instead of DNS client Conduct Inquire about , Until the local name server gets the correct resolution result from the authoritative name server , Then the local name server tells DNS Results of client queries .

In the process of recursive query , Always centered around the local name server ,DNS client Just send the original domain name query request message , And then Waiting all the time Of , until Local name server return The final query result . At this point, the local name server is equivalent to the mediation agent .

If we consider the caching technology of the local name server ( stay DNS Save a certain number of queried records on the server for a certain time , In this way, when querying the same domain name information, it can be directly transferred from the cache , To speed up query efficiency ) Words , The basic process of recursive parsing is as follows ( Here only to first DNS Take server as a local name server as an example , With other standby DNS The parsing process of the server is exactly the same ):

  1. client Configured to this machine Local name server issue DNS Domain name query request .

  2. Local name server Upon receipt of the request , First query the local cache , If there is a record entry for the domain name , Then the local name server will directly return the query results to the client ; If there is no record of the domain name in the local cache , Then the local name server uses DNS The role of the client sends the same DNS The domain name query request is sent to the root name server .

  3. Root name server received DNS After the request , Put the requested DNS The top-level name server address corresponding to the top-level domain name in the domain name is returned to the local name server .

  4. Local name server Based on the top-level name server address returned by the root name server , Send the same... As before to the corresponding top-level name server DNS Domain name query request .

  5. Top level name server Upon receipt of DNS After the query request , It's also First query your own cache , If there is a request DNS Domain name entries , Then the corresponding record item is directly returned to the local name server , Then the local name server returns it to DNS client , Otherwise, return the requested... To the local name server DNS The secondary name server address corresponding to the secondary domain name in the domain name .

  6. Local name server According to the secondary name server address returned by the root name server , Send the same message to the corresponding secondary name server DNS Domain name query request .

  7. Secondary name server Upon receipt of DNS After the query request , It's also First query your own cache , If there is a request DNS Domain name entries , Then the corresponding record item is directly returned to the local name server , Then the local name server returns it to DNS client , Otherwise, return the requested... To the local name server DNS The third level name server address corresponding to the third level domain name in the domain name .

  8. That's it Local name server Repeat step 6 And steps 7 The method goes to three levels again and again 、 Level 4 name server and other queries , until The final domain name corresponds to the region where the domain name is located Authoritative name server Return to the final record to the local name server .

  9. And then by Local name server Return to DNS Customer , meanwhile The local name server will cache The record items obtained from this query .

If in the above steps, the authoritative name server of the corresponding domain name says that the corresponding domain name record cannot be found , Will go to DNS The client returns a query that fails DNS Reply message . Of course , If the authoritative name server is configured with forwarders pointing to other name servers , Then the authoritative name server will further repeat the above steps on the name server pointed to by the forwarder . in addition , If DNS More than one... Is configured on the client DNS The server , Will continue to other DNS The server queries .

Simple speak , Recursive query steps ;

  1. client Configured to this machine Local name server issue DNS Domain name query request , After making a request client Waiting all the time , wait for Local name server Return query results .
  2. Local name server received DNS After the request , First query the local cache , If the domain name record item is found, the result will be returned immediately , otherwise Local name server Keep turning to DNS The name server sends DNS Request query , Until you find the corresponding of the changed domain name Authoritative name server And get the recorded results .
  3. Local name server After parsing the result, return the result to client .

DNS recursive query - Example

For ease of understanding , Give a specific example , to glance at DNS Recursive parsing workflow :

  • Suppose the client wants to visit a site that he doesn't recognize www.google.com, that DNS The query path of the customer service end is as follows :
  1. DNS client To the configured local name server dns.google.com Send resolution www.google.com Domain name DNS Request message .

  2. Local name server Upon receipt of the request , First query the local cache . Suppose no corresponding record of the domain name is found , Then the local name server to the configured root name server a.rootserver.net Send resolution request resolution www.google.com Domain name DNS Request message ( It's equivalent to saying... To the local name server :“ Please give me www.google.com The corresponding IP Address ”).

  3. Root name server received Client's DNS After querying the request message , Get... By querying .com The top-level name server corresponding to the top-level domain name , Then return a reply message to the local name server ( Quite speaking “ I don't know www.google.com The domain name corresponds to IP Address , But I'll tell you now .com The top name server address corresponding to the domain name ”).

  4. Local name server After receiving the from the root name server DNS Reply message , obtain .com After the top-level name server address corresponding to the top-level domain name , Send a request resolution to the corresponding top-level name server again www.google.com Domain name DNS Request message .

  5. .com Top name server is receiving DNS After the request message , First query your own cache , Suppose there is no record item of the domain name , Then check google.com Corresponding secondary name server , Then it also returns a... To the local name service DNS Reply message ( It's equivalent to saying... To the local name server :“ I don't know www.google.com The domain name corresponds to IP Address , But I'll tell you now google.com The secondary name server address corresponding to the domain name ”.

  6. Local name server Upon receipt of .com Top name server DNS Reply message , obtain google.com After the secondary name server address corresponding to the secondary domain name , Send a request resolution to the corresponding secondary name server again www.google.com Domain name DNS Request message .

  7. google.com The secondary name server is receiving DNS After the request message , also First query your own cache , Suppose there is no record item of the domain name , Then check www.google.com The corresponding authoritative name server , Then it also returns a... To the local name server DNS Reply message ( Equivalent to the local name server :“ I don't know www.google.com The domain name corresponds to IP Address , But I'll tell you now www.google.com The authoritative name server address corresponding to the domain name ”).

  8. Local name server Upon receipt of google.com Secondary name server DNS Reply message , obtain www.google.com After the authoritative name server address corresponding to the third level domain name , Send a request resolution to the corresponding authoritative name server again www.google.com Domain name DNS Request message .

  9. www.google.com`` Authoritative name server Upon receipt of DNS After the request , In its DNS Look up... In the area database , Finally came to www.google.com The domain name corresponds to IP Address . Then return to the local name server DNS Reply message ( It's equivalent to saying... To the local name server :“www.google.com Domain name IP The address is xxx.xxx.xxx.xxx”).

  10. Local name server stay received Authoritative name server After the response message , towards DNS client return One DNS Reply message , tell DNS What the client gets www.google.com Domain name IP Address . such DNS The client can access the website normally .

PS:DNS Is based on UDP Make a query , You can also consider why you didn't consider using TCP To achieve .

Related literature

copyright notice
author[JyLie],Please bring the original link to reprint, thank you.
https://en.fheadline.com/2022/02/202202031617352424.html

Random recommended