DNS query mechanism

First look at the domain level: to Baidu as an example: www.baidu.com. The order is com(top-level domain name), baidu(first-level domain name), www(second-level domain name). But there is actually a unique root domain name root:, www.baidu.com.rootbut because it rootis unique, it is rootnot particularly necessary whether to write the root domain name.

1. What is DNS

DNS:Domain Name System, That is, the domain name system, which is mainly used to manage and query the IP address corresponding to the domain name. In real life, when you enter a certain URL on a web page www.baidu.com, the browser does not only use www.baidu.comthis domain name to access the corresponding server and request the content. The browser needs to have the IP address of the corresponding server, then how to get the domain name IPWhat about the corresponding address? At this point, DNSit works here. The browser passes the domain name www.baidu.comto the domain name server DNS, DNSfinds the corresponding ipaddress and sends it to the browser, and the browser can ipaccess the corresponding server through the address to obtain the content.

2. DNS working mechanism

We started from entering the domain name in the browser to obtaining the real ip address, and looked at the whole work flow, so as to understand the role of DNS in it.

First enter the domain name in the browser:, the www.baidu.combrowser will first look up the record in the browser's own DNS cache. If it finds the record related to this domain name, it will directly access the corresponding ip address. If it can’t be found, the browser will go to the local computer to find the hostsfile and find the relevant record of this domain name. If the search is successful, it will directly access the IP address, otherwise the browser will query the DNS server address set in the current computer settings, generally After the computer is connected to the network, the DNS server address is automatically set (you can also manually set the known DNS server address), that is, the router that the device is connected to is assigned by default, but the automatically set DNS server IP address, Generally, it is the IP address of the router that manages WiFi.

Assuming that automatic setting is adopted, the ip address obtained by the browser in the network settings is a routing ip, it will initiate a DNS query request to the corresponding router. At this time, after the router receives the DNS query request, it will forward the request to the optical modem ( As long as the optical modem is connected to the server network, it will be assigned the corresponding DNS server IP), and the optical modem will forward it to the operator's DNS server, usually Local DNS Server(DNS server, closest to the current browser address), responsible for domain name query.

At this point, Local DNS Serverfirst query on your own server to see if there is any www.baidu.comdomain name corresponding information. If yes, return the corresponding ip address to the browser. Otherwise, send the query request to the Root DNS Server. Local DNS ServerHow do you get it Root DNS Server?

Since Root DNS Serverthere are only 13 in the world, its information is generally built in other DNS servers. Root DNS ServerWhich one will you visit ? The DNS server will root DNS Serverinitiate a query to each top-level domain name request. Which one of the information arrives first will use the information returned by which one.

So what is root DNS serverit? root DNS ServerThe ip address information of the DNS server of each top-level domain name is recorded in. Therefore, it local DNS Serverwill first go to the information root DNS Serverin the inquiry , comand then Local DNS serverreceive comthe DNS IP address of the top-level domain name, that is Top Level Server(com top-level domain name server, DNS server that records the first-level domain name)

At this time, I Local DNS Serverwent to visit again Top Level Server, asked about baidu.comthe information, and then Local DNS Serverreceived about baidu.comthe DNS ip address responsible for the first-level domain name, that is Name DNS Server(record the complete domain name, and finally find the place where the ip address is)

Finally, I Local DNS Servergot the IP address from the Name DNS Serverplace www.baidu.comand passed it to the browser.

It can be seen that the DNS query mechanism mainly relies on the hierarchical organization of the domain name. First comquery from the top-level domain name , then query the baidu.comfirst-level domain name, and finally the complete domain name www.baidu.com, and each layer corresponds to the root DNS Server、Top DNS Server、Name DNS ServerDNS server, and these servers are recorded management The IP address of the DNS server of the next-level domain name is the IP address of the DNS server that Root DNS Servermanages different top-level domain names, such as the servers corresponding to these top-level domain names such as com, org, and net. Top DNS ServerIt records the IP addresses of DNS servers that manage different first-level domain names. For example, this DNS server is the server responsible for all com top-level domain names. It records the baidu.com、bing.comIP addresses of a series of DNS servers that manage these first-level domain names.

Guess you like

Origin blog.csdn.net/chen__cheng/article/details/114729437