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.root
but because it root
is unique, it is root
not 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.com
this 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 IP
What about the corresponding address? At this point, DNS
it works here. The browser passes the domain name www.baidu.com
to the domain name server DNS
, DNS
finds the corresponding ip
address and sends it to the browser, and the browser can ip
access 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.com
browser 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 hosts
file 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 Server
first query on your own server to see if there is any www.baidu.com
domain 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 Server
How do you get it Root DNS Server
?
Since Root DNS Server
there are only 13 in the world, its information is generally built in other DNS servers. Root DNS Server
Which one will you visit ? The DNS server will root DNS Server
initiate 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 server
it? root DNS Server
The ip address information of the DNS server of each top-level domain name is recorded in. Therefore, it local DNS Server
will first go to the information root DNS Server
in the inquiry , com
and then Local DNS server
receive com
the 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 Server
went to visit again Top Level Server
, asked about baidu.com
the information, and then Local DNS Server
received about baidu.com
the 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 Server
got the IP address from the Name DNS Server
place www.baidu.com
and 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 com
query from the top-level domain name , then query the baidu.com
first-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 Server
DNS 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 Server
manages different top-level domain names, such as the servers corresponding to these top-level domain names such as com, org, and net. Top DNS Server
It 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.com
IP addresses of a series of DNS servers that manage these first-level domain names.