This is the sixth day of my participation in Gwen Challenge

The DNS records

DNS records refer to the mapping between domain names and IP addresses. Depending on the usage scenario, there are different types of records:

  • A Record: Address record. If A domain name is configured with A record, DNS will resolve the domain name to the IP address specified by A record.

  • CNAME record: Specification name record. If a domain name is configured with a CNAME record, DNS will resolve the domain name to another domain name specified by the CNAME record. A records and CNAME records are mutually exclusive and cannot coexist

  • NS records: DNS records. Returns the address of the server that stores the next-level domain name information. It specifies which DNS server should resolve the domain name.

  • MX records: Mail records. Returns the address of the server that received the E-mail.

  • PTR record: Reverse query records. This command is used only to query domain names from IP addresses.

Working mechanism of DNS (without CDN)

We type the domain name directly into the browser, but the browser must know the IP address of the server in order to establish a TCP connection and send an HTTP request. How to find the IP address of the server based on the server domain name?

  1. Enter join.qq.com in the address box and press Enter
  2. The browser extracts the domain name join.qq.com from the URL and checks whether the domain name is mapped to the IP address in the browser cache (Chrome ://net-internals/# DNS). If no, go to the next step
  3. Check whether the mapping between the domain name and IP address exists in the operating system cache (ipconfig/displaydns on the command line). If no, go to the next step
  4. Check whether there is a mapping between the domain name and IP address in the host file. If no, go to the next step
  5. Sends a query request to the local DNS to check whether the local DNS caches the mapping between the domain name and the IP address. If no, go to the next step and start iterative domain name resolution
  6. The local DNS sends the domain name to the root DNS, which finds that the domain name contains com and returns the IP address of the top-level DNS responsible for resolving COM
  7. The local DNS sends the domain name to the top-level DNS. The top-level DNS finds that the domain name contains qq.com and returns the IP address of the authoritative DNS responsible for resolving qq.com
  8. The local DNS sends the domain name to the authoritative DNS. The authoritative DNS finds that the domain name contains join.qq.com. The authoritative DNS searches for A record and returns the IP address to the local DNS
  9. The local DNS sends the IP address back to the browser
  10. From there, the browser has the server’s IP address, establishes a TCP connection with the server through a three-way handshake, and then sends an HTTP request

PS: the top-level DNS resolves.com, the authoritative DNS resolves join.qq.com, so what is the root DNS to resolve at the beginning? Root is the common suffix for all domain names, join.qq.com is actually join.qq.com.root, but it is usually omitted.

Working mechanism of DNS (introducing CDN)

In long-distance communication, communication efficiency is very low, so CDN is generally used — proxy servers are set up at multiple nodes around the world, and the client sends requests to the proxy server nearby (rather than the source server).

Some concepts to understand about CDN:

  • Hit and return source: when the node server in the CDN just caches the resources required by the client and does not expire, it is called hit cache. Otherwise, the node server still needs to forward the request to the source server and back to the source server for the resource, which is called back to the source.

    Hit and backsource correspond to hit ratio and backsource ratio respectively, which are two indicators to measure the quality of CDN. Obviously, a good CDN should have a high hit rate and a low back source rate.

  • Classification of CDN:

    • According to the topology: one is distributed CDN, that is, deploy as many proxy servers as possible in the world; The other is the integrated CDN, which only has a small number of nodes in the main data center, but the node performance is more powerful, including network, throughput and anti-ddos capabilities.
    • According to the content distribution mode, the CDN is Push and Pull. In the former, the content server pushes the content to CDN in advance. The CDN pulls the target resource and caches it when the user accesses the content

With the introduction of CDN, we no longer send requests to the source server, so we no longer need the IP address of the source server, so the DNS resolution process has also changed.

First, the previous steps are the same:

  1. Enter join.qq.com in the address box and press Enter
  2. The browser extracts the domain name join.qq.com from the URL and checks whether the domain name is mapped to the IP address in the browser cache (Chrome ://net-internals/# DNS). If no, go to the next step
  3. Find if there is a mapping between the domain name and IP address in the local cache (ipconfig/displaydns on the command line). If no, go to the next step
  4. Check whether there is a mapping between the domain name and IP address in the host file. If no, go to the next step
  5. Sends a query request to the local DNS to check whether the local DNS caches the mapping between the domain name and the IP address. If no, go to the next step and start iterative domain name resolution
  6. The local DNS sends the domain name to the root DNS, which finds that the domain name contains com and returns the IP address of the top-level DNS responsible for resolving COM
  7. The local DNS sends the domain name to the top-level DNS. The top-level DNS finds that the domain name contains qq.com and returns the IP address of the authoritative DNS responsible for resolving qq.com

From step 8 onwards, something has changed:

  1. The local DNS sends the domain name to the authoritative DNS. The authoritative DNS finds that the domain name contains join.qq.com and searches for the CNAME record and its corresponding A record. CNAME record name is domain name, value is an alias of the domain name, indicating A global load balancing system (GSLB), and A record name is the alias, value is the IP address of the GSLB. The authoritative DNS eventually returns the IP address to the local DNS
  2. The local DNS sends a request to the GSLB. The GSLB calculates the location of the local DNS based on its IP address, finds the optimal local load balancing system (SLB) in this location, and returns the IP address of the SLB to the local DNS
  3. The local DNS sends the IP address back to the browser
  4. The browser sends a request to the SLB. SLB considers various factors (distance, load, response speed, health, etc.) to find the best proxy server node and returns the IP address of that node
  5. The browser sends a request to this node
  6. The node determines whether the resource requested by the browser exists in its cache, and if so, whether the resource has expired. If the resource exists and does not expire, it is matched. Otherwise, you need to return to the source

DNS Optimization Scheme

  1. Reduce the number of DNS requests
  2. DNS preresolution:
<meta http-equiv="x-dns-prefetch-control" content="on">
<link rel="dns-prefetch" href="//www.img.com">
<link rel="dns-prefetch" href="//www.api.com">
<link rel="dns-prefetch" href="//www.test.com">
Copy the code