It is the recruitment season again. Two days ago, I met a small partner of the interview. He said that the interviewer chatted with him very speculatively and accidentally talked about the process of DNS request. He temporarily speechless casually dealt with two sentences, although the other side did not ask the meaning, but the final interview result is not ideal. With a learning as you interview attitude, let’s take a look at the definitions and principles involved in the DNS request process.

The meaning and structure of DNS

It is well known that IP is used to identify a server on the Internet. Although the IP address can represent a device, it is difficult to remember, so it is replaced by a name that can be understood and recognized. This name is called the domain name. For example, www.51cto.com is a domain name that defines an IP address that points to the Web server. So the question is, who’s going to do the mapping from domain name to IP address? The answer is through DNS.

DNS is the Domain Name System (DNS), a service of the Internet. It will be a domain name and IP address mapping each other of a distributed database, in the database to save the domain name and IP contrast relationship, so that people more convenient access to the Internet.

DNS resolution is distributed, structurally at the top, the Root DNS Server, which stores the IP addresses of 260 top-level DNS servers. For IPv4, there are 13 root DNS in the world, which stores the resolution of each domain (e.g., com.net.cn) and the DNS address information. Simply put, the root domain name server is where the top-level domain name server address resides.

One level below the root domain name server is the top-level domain name server. For example, the DNS server of.com stores the authoritative DNS server addresses of some top-level domain names (such as the DNS of toutiao.com).

TLDs, also known as first-level domain names, can be divided into three categories, namely gTLD, ccTLD and New gTLD:

  • GTLD: Generic Top-level Domains (GTLD), such as.com/.net/.org, belong to GTLD;
  • CcTLD: Country code top-level domains (ccTLD), e.g. CN for China and.jp for Japan;
  • New gTLD: New top-level domain (New gTLD), such as.xyz/.top/.red/.help.

The top-level domain server stores IP data according to the above three categories.

One level below the TLDs is the Local DNS, which is typically the operator’s DNS and is used to perform domain name analysis on behalf of the user.

As shown in Figure 1, DNS domain name servers are divided into three levels: Root DNS Server, top-level DNS Server (gTLD, ccTLD, New GTLD), and Local DNS Server from top to bottom.

Fig. 1 DNS hierarchical structure

DNS parsing principle

Say the structure of DNS, and then talk about its operation principle. The whole process of DNS parsing and obtaining URL-IP mapping is described through the process of the user visiting the web page. The process is relatively complex, there will be information back and forth. In the process of drawing, we will simplify the line segment of information transmission back and forth, focus on the path of information transmission, and interpret the DNS parsing process through 9 steps.

图片Figure 2 The whole process of user request and DNS resolution

  • 1. The user requests to enter the address of the website through the browser, such as: www.51cto.com. The browser looks up the IP address of the URL in its own cache. If you have previously accessed this URL and have a cache of the IP address, then access the IP address directly. If there is no cache, go to step 2.
  • 2. The mapping relationship between URL and IP address can be set through the local Host file configuration of the computer. Such as Windows via C: windwossystem32driveretchosts file to set up, in Linux is/etc/named confg file. Look for the local Host file and see if there is an IP address in the cache. If the mapping is still not found in the file, proceed to step 3.
  • 3. Request the Local DNS Server and obtain the mapping relationship between URL and IP through the Local operator. If it is on a campus network, the DNS server is at the school. If it is on a cell network, the DNS server is provided by the operator. In short, the server is physically close to the machine that initiated the request. Local DNS servers cache a large number of DNS parsing results. Due to its high performance and physical proximity, it usually returns the resolution results of the specified domain name in a short time. Eighty percent of the DNS resolution requirements are met in this step. If the DNS resolution is not complete at this step, proceed to step 4
  • Root DNS Server will return the address of the Local DNS Server based on the requested URL. For example, if you are looking for a “.com “domain name, you will be looking for the address of the domain name server corresponding to GTL.
  • 5, After returning the address of the top-level domain Name Server, access the corresponding top-level domain Name Server (gTLD, ccTLD, New gTLD), and return the Name Server Server address. The Name Server is the domain Name Server registered by the website, which contains the URL and IP corresponding information of the website. For example, if you apply for a domain name from a domain name service provider, the domain name is resolved by their server. The Name Server is maintained by the domain Name provider.
  • 6, The Name Server returns the A record or CNAME of the specified domain Name to the Local DNS Server, and sets A TTL.
The A (Address) record is used to specify the IP Address record corresponding to the hostname (or domain name). Users can point the Web server under this domain name to their own Web server. You can also set the second level of your domain name. CNAME: Alias record. This record allows you to map multiple names to another domain name. Usually used for computers that provide both WWW and Mail services. For example, there is A computer named "host.mydomain.com" (A record). It provides both WWW and Mail services in order to facilitate user access to the service. Service providers from the point of view of convenient maintenance, generally also suggest that users use CNAME records binding domain name. If the host uses a two-wire IP, it is obviously easier to use a CNAME as well. TTL (Time To Live) : Set the expiration Time of the DNS resolution on the Local DNS Server. After this expiration time, the mapping between the URL and the IP is removed, and the Name Server needs to be fetched and requested.
  • 7, If the A record is obtained at this time, then you can directly access the IP of the website. But typically large websites will return a CNAME and pass it to the GTM Server.

GTM (short for Global Traffic Manager) stands for Global Traffic management. Based on network intelligent DNS and distributed monitoring system, GTM realizes real-time fault switching and Global load balancing to ensure continuous high availability of application services. The purpose of passing to GTM is to help users find the most suitable server IP through the load balancing mechanism of GTM.

That is, the closest, the best performance, the healthiest server state. And most of the websites will do CDN cache, at this time you need to use GTM to help you find the network node for your CDN cache server.

  • 8. After finding the CDN cache server, you can directly get some static resources from the server, such as: HTML, CSS, JS and pictures. However, some dynamic resources, such as commodity information, order information, need to go through step 9.
  • 9. For uncached dynamic resources that need to be retrieved from the application server, there is usually a layer of load balancer between the application server and the Internet that is responsible for the reverse proxy. There is a route to the application server.

conclusion

NS server is used to do URL and IP address resolution, to help users find the IP to access the server. From the structure of DNS server is roughly divided into three layers: root domain name server, top-level domain name server, local domain name server.

The provider applying for the domain Name will provide the Name Server for DNS resolution. From a user visiting a website, going through a browser, Local Host File, Local DNS Server, Root DNS Server, TLDs (GTLD, CCTLD, NEW GTLD), Name Server, GTM, CDN, Application Server. There are nine steps.

Author: Cui Hao 51CTO


Source:https://blog.51cto.com/142793…