This article was first published on the public account [an old code farmer]

  • What is DNS resolution

The full name of the DNS is Domain Name System. DNS resolution is also called domain name resolution. In the previous article, we said that on the Internet, access to a computer is ultimately through IP. There is a mapping between domain names and IP addresses. Websites accessed through domain names are eventually converted to IP addresses for access. The whole process of resolving an IP from a domain name is called DNS resolution. DNS resource information is stored on the DNS server.

  • Root DNS server

There are 13 root DNS servers in the world, including a primary root server and 12 secondary root servers. One primary root server plus nine secondary root servers are in the United States; Three other secondary root servers, including two in The UK and Sweden in Europe; Asia 1 is in Japan.

13 root DNS servers, not 13 physical servers. There are many physical servers running behind each root DNS server. Each root server has several mirror root servers distributed around the globe.

  • DNS Resolution Process

Before we talk about the DNS resolution process, let’s take a look at the composition of a domain name. A domain name consists of two or more parts, separated by “. Segmentation. The last point is called a top-level domain, and the subdomains of a top-level domain are called second-level domains. The subdomains of the second level domains are called third level domains. For example, the domain name www.xxxx.com, where.com is what we call a top-level domain name; Xxxx.com is the subdomain name of.com, that is, the second-level domain name. www.xxxx.com is the subdomain name of the secondary domain name, where WWW is the host name.

DNS resolution is divided into iterative query and recursive query.

Iterative query

Iterative query is to obtain the authoritative DNS server address of the subdomain name step by step and obtain the IP address of the domain name through the authoritative server address. The process is as follows:

1. The client sends a request to the local DNS server to query the IP address of www.xxxx.com. (The local DNS is the DNS configured on the PC. After receiving the request, the local DNS server sends a resolution request to the root DNS server to query the IP address of www.xxxx.com. The root DNS server returns the. Com top-level DNS server address 4. After receiving the response, the local DNS server sends a resolution request 5 to the TOP-LEVEL domain name server. After the top-level DNS server receives the request, it returns the authoritative DNS server address 6. After receiving the response, the local DNS server sends a resolution request to the authoritative domain name server. Xxxx.com. After receiving the request, the authoritative domain name server returns the IP address of the domain name corresponding to www.xxxx.com to local DNS server 8. The local DNS returns the IP address of the domain name to the client and caches it

Iterative query flow chart:

Recursive query

In recursive query, DNS servers at all levels are accessed recursively. IP addresses are returned to clients recursively. The process is as follows:

1. The client sends a request to the local DNS server to query the IP address of www.xxxx.com 2. The local DNS server sends a resolution request to the root DNS server. 3. After receiving the request, the root DNS server sends a query request to the.com top-level DNS server. After receiving the request, the com top-level DNS server sends a query request to the authoritative.xxxx.com server. 5.. Xxxx.com returns the IP address corresponding to www.xxxx.com to.com top-level DNS server 6. The top-level DNS server returns an IP address to the root DNS server 7. The root DNS server returns an IP address to the local DNS server 8. The local DNS server caches the IP address and returns it to the client

Flow chart:

  • DNS Resource Records

Common DNS server resource records include A record, NS record, and CNAME record

1.A Record A record refers to the record of the domain name and its corresponding IP address. It is because of A record that domain names can be resolved successfully. If the address is an ipv6 address, you need to add AAAA records.

2.NS Records NS records, called DNS records, specify the DNS server for subdomain name resolution

3.CNAME Record The CNAME record is called an alias record and is generally used to specify the alias of a domain name. For example www.baidu.com, there is an individual named www.a.shifen.com.

  • Problems with traditional DNS

1.DNS hijacking Because traditional DNS is transmitted through UDP in plaintext, UDP data transmission is unreliable, which may be hijacked by phishing DNS servers to resolve incorrect IP addresses.

2. Domain name forwarding For example, carrier A forwards resolution requests to carrier B to save costs. Carrier B’s IP address corresponding to the domain name is returned, causing cross-carrier access and affecting the access speed.

3. Resolution delay Because the DNS query process requires multiple DNS servers to obtain the IP address, both recursively and iteratively. This may cause resolution delay, which is more obvious if the DNS server is far away from the client.

  • HttpDNS

In order to solve the problems of traditional DNS, people introduced the HttpDNS domain name resolution solution, HttpDNS does not go through the traditional DNS resolution, but through HTTP request directly to obtain the corresponding IP address of the domain name, so that can solve the problem of traditional DNS may be hijacked. Because the client request is HttpDNS server, do not go to the operator’s local DNS, so there is no domain name forwarding problem and its DNS server cluster distributed in multiple locations multiple operators, it can choose the best service node to resolve according to the client’s country, province, operator and other information. This also solves the DNS resolution delay problem to a certain extent. Now Tencent, Ali, Google and other companies have their own HttpDNS services. I also used Ali’s HttpDNS service in the project, which greatly improved the access speed of foreign users. You can select an appropriate HttpDNS service based on your actual situation.

Pay attention to the public number [an old code farmer], more high-quality technical content waiting for you

The original address