1. Why is DNS resolution required?

Domain Name System (DNS) : At first, it was not convenient to access websites through IP addresses because they were long and difficult to remember. Later through the invention of DNS server, at this time we can access the website by entering the website domain name www.baidu.com, DNS server will resolve our domain name into IP address. So we’re actually accessing the corresponding IP address. DNS is an application-layer protocol that uses UDP to transmit data

In the abstract, DNS is a super-distributed database that records IP addresses.

Let’s talk about some basic concepts of DNS:

  1. The root domain

In fact, our website www.baidu.com should be www.baidu.com. (there is one last point), and it has become a habit to omit the dot when typing in the browser (because all domain names come after it, so it can be omitted).

We know there are 13 root domain servers, but that's wrong.

The root domain server only has 13 IP addresses, but there are not 13 machines, because these IP addresses are using anycast technology, so we can set up mirror sites of these IP addresses around the world, and the IP that you visit is not the only host. You can refer to Wikipedia for a detailed mirror distribution. The content of these hosts is the same

  1. The division of the domain

The root domain comes down to the top-level domain or the first level domain,

List two ways of division. One is com. and NET, which were divided according to the nature of the industry when the Internet was just emerging. Etc., the other is divided by country such as CN., JP., US., UK.

Each domain has a domain name server, also known as an authoritative domain name server.

For example, baidu.com is a top-level domain,.com is a top-level domain, and www.baidu.com is not a top-level domain. It is a host called WWW in the domain of Baidu.com.

If I buy a top-level domain, and I set up my BIND server (or any other software) and register it with the Internet, I can add as many fields as I want (of course, the length is limited).

For example, xzp.www.baidu.com, where www.baidu.com becomes a three-level domain instead of a host with the name XZP.

3. Domain name serverCopy the code

A server that can provide domain name resolution. The record types can be A(Address) record, NS record (Name Server), MX record (mail), CNAME, etc.

Suppose that A domain name server resides in the domain test.baidu.com. We know that this is A second-level domain name. Then there is A record of A, which records the IP address of host A. If it is found, it will be returned to you.

If I now want to query a.test.baidu.com, the top-level domain name server will find that the url you requested is in the test.baidu.com domain. The NS IP address of the secondary domain server test.baidu.com is recorded here. I’m going to give you this IP address and you’re going to go to this secondary DNS server and look up the IP address of host NAME A.

4. The parsing processCopy the code

When a user enters www.163.com in the address bar, the DNS resolution process is roughly 11, as follows:

  1. The browser checks whether the IP address corresponding to the resolved domain name exists in the cache. If yes, the resolution is complete.

  2. Search for the DNS cache of the operating system: If the browser does not find the CACHE or the cache expires, the browser searches for the CACHE of the operating system. If the cache does not find the cache or the cache expires, the parsing ends.

  3. Read the local hosts file: If the cache of the operating system is not found or invalid, the browser reads the local hosts file. (The hosts file can also set up binding relationships between domain names and IP addresses. You can edit the hosts file to resolve the names. For example, if we want to block a domain name, we can point the address to a non-existent IP address.

  4. If so far has not hit the domain name, will be the real request local domain name server (LDNS) to resolve the domain name, this server in your corner of the city, not far away from you, and this server performance is very good, generally caching DNS results, about 80% of the DNS here is done.

  5. If the LDNS still does not hit, the root DNS server is directly jumped to request resolution

  6. The root DNS server returns a.com top-level DNS server IP address to the LDNS

  7. LDNS then sends the request to.com

  8. The requested.com domain Name Server looks up and returns the IP address of 163.com’s Name Server, which is the domain Name Server registered for the site

  9. LDNS then sends the request to the taobao.com domain name server, which finds the target IP address based on the mapping table and returns the request to LDNS

  10. LDNS caches this domain name and the corresponding IP

  11. The LDNS returns the resolution result to the user. The user caches the resolution result to the local system cache based on the TTL value. The domain name resolution process is complete