Let's talk about several basic DNS concepts:
1. Root Domain
Is the so-called ". in fact, our website www.baidu.com should be www.baidu.com. (Last point), we usually omit the following points when entering them in a browser, which has become a habit.
We know 13 root domain servers, but this is a wrong idea.
The Root Domain Server only has 13 IP addresses, but the number of machines is not 13. Because these IP addresses use the anycast technology, we can set up image sites for these IP addresses globally, the IP address you accessed is not the only host.
For more information about image distribution, see Wikipedia. The contents of these hosts are the same.
Ii. Division of Domains
The root domain is a top-level domain or a top-level domain,
There are two ways to divide the com ., net. and so on. One is by country, for example, CN ., JP .,.
You can check the specific quantity by yourself. We don't care about it here.
Each domain has a Domain Name Server, also called an authoritative Domain Name Server.
Baidu.com is a top-level domain name, while www.baidu.com is not a top-level domain name. It is a WWW host in the Baidu.com domain.
After the first-level domain, there are second-level domain and third-level domain. As long as I have bought a top-level domain and I have set up my own BIND server (or other software) to register it on the internet, then I can add a few more fields at Will (of course, the length is limited ).
For example, in a.www.baidu.com, www.baidu.com becomes a second-level domain instead of a host, and the host name is.
Iii. Domain Name Server
The server that can provide domain name resolution. The above record types can be a (Address) record, NS record (Name Server), MX (mail), cname, etc.
(For details, refer to the blog: what are the differences and connections between a record, cname, MX record, and NS record in domain name resolution)
What does a record mean? It records an IP address and a host name, for example, test.baidu.com, the domain where my domain name server is located. We know that this is a second-level domain name, then I have a record a in it, record the IP address of host a, and return it to you.
If I want to query a.test.baidu.com on the Domain Name Server, the top-level domain name server will find that the URL you requested is in the domain test.baidu.com, I have recorded the NS IP address of the second-level domain name server test.baidu.com. I will return this address to you and check the host as a host.
Domain name servers in these regions are called authoritative servers and directly provide DNS query services. (These servers do not do recursion)
Iv. parsing process
So how does our DNS resolve a domain name?
1. Now I have a computer that connects to the Internet through the ISP, then the ISP will allocate a DNS server to me,This DNS server is not an authoritative serverIt is equivalent to a proxy DNS resolution server. It will help you iterate the response returned by the authoritative server, and then return the IP address finally found to you.
2. my computer is about to send a request to this ispdns to query the domain name www.baidu.com. (according to a user's reminder, it is actually not ispdns, but the DNS in the network settings of the user's computer, not necessarily ispdns. For example, you may have manually set 8.8.8.8)
3. After ispdns receives the request, it first checks whether the address exists in its cache. If yes, it returns directly. The IP address obtained at this time will be markedNon-authoritative server response.
4. If the cache does not exist, ispdns willConfiguration FileIt reads the addresses of 13 root domain name servers (these addresses remain unchanged and are directly in the BIND configuration file ),
5. Then, initiate a request like one of them.
6. After receiving the request, the root server will know that it is under the top-level domain name com. Therefore, it will return the NS record in the com domain, generally 13 host names and IP addresses.
7. then, ispdns initiates a request to one of them. The server in the com domain finds that the request belongs to the Baidu.com domain. Once I find the NS in this domain, I will return it to you, check again.
(Baidu currently has four top-level domain name servers of Baidu.com ).
8. ispdns repeatedly initiates a request to the authoritative server in the Baidu.com domain. After receiving the request, Baidu.com checks the host with WWW and returns the IP address to you,
9. After ispdns is obtained, it is returned to the client and saved in the cache.
Next we will use the NSLookup tool to describe the parsing steps in detail:
We can see that:
The first line of server is: DNS server host name -- 210.32.32.1
The second line of address is: its IP address -- 210.32.32.1 #53
The name below is: resolved URL -- www.jsjzx.com
Address is: the parsed IP--112.121.162.168
But there are also complex DNS resolutions like Baidu:
You will find that Baidu has an alias for cname = www.a.shifen.com.
How is this process?
We use the dig tool to trace (Linux system comes)
Zookeeper ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
The Dig tool performs iteration on the local computer and then records the Query Process.
The first step is to obtain the 13 IP addresses and host names of the root domain service from ispdns on my machine [B-J] .root-servers.net ..
The second step is to send a query request www.baidu.com to one of the root domain servers (servername is included in the last line of parentheses. the server IP address (not displayed) and name of the top-level domain,
Step 3: send a request to a server in the com. domain, www.baidu.com, and return the IP address (not displayed) and name of the server in the Baidu.com domain. Baidu has four top-level domain servers.
[Here, you can use dig @ 192.33.4.12 www.baidu.com to view the IP address of the returned Baidu top-level domain name server ].
Step 4: Request www.baidu.com from Baidu's top-level domain server (202.108.22.220). He found that the WWW has an alias instead of a host, and the alias is www.a.shifen.com.
Zookeeper ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
According to the general logic, when the DNS requests an alias, the query will be terminated, but the query alias is re-initiated. Therefore, www.a.shifen.com should be returned here.
But why is the NS returned from the.shifen.com domain?
We can try the following command: Dig + trace shifen.com to see what the result is ........
In step 3, you will find that the Domain Name Server of shifen.com and the Domain Name Server of Baidu.com are the same host (dns.baidu.com )!
When I got the alias www.a.shifen.com for www.baidu.com, I had to go back to the com domain to find the NS OF THE shifen.com domain, but because the two domains are on the same NS, therefore, it is directly initiated to the local machine,
The request www.a.shifen.com belongs to the.shifen.com domain,
So I will return the NS and IP address of a.shifen.com, and ask me to query www.a.shifen.com on the Domain Name Server of a.shifen.com.
So I got a record from one of NS x .a.shifen.com, and finally the IP address of www.baidu.com. [here we can also use dig + trace www.a.shifen.com to trace it.
A graph is used to illustrate the situation (in the third step, only 13 servers in the world are incorrect)
The following describes the experiment data obtained by setting up a local DNS server on a virtual machine.
In the above analysis, we used the dig tool for tracking, but dig did not continue to track things after we obtained the IP addresses of cname and ns2.a.shifen.com from Baidu.com.
We can conclude that local DNS will request www. A. shifenc. Om from ns2.a.shifen.com.
In fact, this idea is wrong. Set up a local DNS in your own Local Machine and capture all the packages in the entire parsing process.
The actual result is that although dns.baidu.com returns the server address and IP address of the.shifen.com domain,
However, the local DNS does not directly request www.a.shifen.com from the returned IP address, but again requests the com domain to obtain the server of the shifen.com domain (that is, the four servers of Baidu.com ),
Then request www.a.shifen.com, return the server of the.shifen.com domain, and finally request www.a.shifen.com,
Although the IP address has been returned, the result of the experiment is to go through the shifen.com domain query again.
It is the whole process for localdns to capture packets after www.baidu.com is resolved. The blue one is to request shifen.com from the com domain after receiving the IP address of the Domain Name Server of the cname and the response a.shifen.com.
This figure shows that the ns2.a.shifen.com IP address is returned when the cname is returned.
So the summary is:
① The Local Machine requests www.baidu.com from the local DNS
② Local DNS requests www.baidu.com from the root domain, and the root domain returns the IP address of the server in the com. domain.
③ Request www.baidu.com from Com. domain, and return the Server IP address of Baidu.com from Com. domain.
④ Request www.baidu.com from Baidu.com and return the IP addresses of servers in the cname www.a.shifen.com and a.shifen.com Domains
⑤ Request www.a.shifen.com from the root domain
6. Request www.a.shife.com from Com. Domain
7. Request to shifen.com
Requests from region to a.shifen.com
⑨ Get the IP address of www.a.shifen.com
⑩ Localdns returns the IP addresses of the Local Machine www.baidu.com cname www.a.shifen.com and www.a.shifen.com.
Reference: cryinstall.com