Reason for writing
Gay foundation series is based on their own learning and work experience as the starting point to do some knowledge summary, and strive to build their own knowledge system network, not exhaustive, as long as the key breakthrough.
What is the DNS
DNS, the Domain name System. In the current network system, any end system is marked by an IP address. Currently, the default ipv4 address is 32 bits, generally expressed in dotted decimal notation 192.168.0.1. The problem is that such a number is hard to remember. You need to remember baidu’s IP address 61.135.169.125, and remember that this string of numbers is actually somewhat anti-human. Therefore, we use a more consistent with the way of human thinking to visit Baidu, directly enter www.baidu.com in the browser, compared with the number, this string of words is easier to remember, this is the host name (here the host name can be equated with the domain name). Routers like fixed-length, hierarchical IP addresses, and humans like to remember host names, so the domain name system provides a compromise. The domain name system (DNS) mainly provides a directory service that translates host names into IP addresses.
Other services provided by DNS
DNS is an application-layer protocol in client-server mode. It usually uses UDP as the transport layer protocol and runs on port 53. It mainly provides a directory service that translates host names to IP addresses. In addition, there are other services based on this feature.
1. Set an alias for the host
A host may have multiple domain names bound to the IP address of the host, assuming that both www.baidu.com and www.baidu1.com have access to 61.135.169.125, www.baidu.com is the standard host name for this host, So www.baidu1.com is the alias of the host. Some aliases are better remembered than regular host names. DNS can provide a mapping from aliases to regular host names and IP addresses.
2. Mail server alias
The principle is similar to aliasing a host, but I won’t go into details.
3. Load allocation
A site (such as Baidu.com) may be distributed on multiple servers, each running on a different end system, each with a different IP address. So the host name is associated with a set of IP addresses. When a client initiates a domain name resolution request, the DNS server returns the corresponding set of IP addresses in response, but circulates the order of addresses in each response, because the client usually sends the request to the first server in the set of IP addresses, so the DNS implements load distribution.
The working principle of
Organizational form
DNS does not use a single point of storage, the main points are as follows
1. A single point is prone to failure
2. Communication capacity is limited because all DNS requests need to be processed
3. Remote centralized database will lead to long delay
4. Difficult to maintain.
DNS uses a distributed multi-level database
Roughly speaking, there are three types of DNS servers: root DNS server, top-level DOMAIN DNS server, and authoritative domain DNS server. For example, if you want to query the IP address of www.baidu.com, the client (usually the local DNS server) will send a request to the root DNS server. Then the root DNS server will return the IP address of the top-level DNS server of com. Then the client will send a DNS request to the top-level DNS server. The top-level DNS server returns the IP address of the authoritative DNS server based on Baidu.com. The client sends a request to the authoritative DNS server, and the authoritative DNS server returns the final IP address. From this analysis, we know that
Root DNS server: Stores the IP address of the top-level DNS server
Top-level DOMAIN DNS server: Stores the IP address of the authoritative DOMAIN DNS server
Authoritative domain DNS server: Stores DNS records, that is, the mapping of each domain name to an IP address.
The analysis process is shown in the following figure
Figure 1 is an iterative query, and Figure 2 is a recursive query, both of which can happen.
Local DNS Server
Can see the two pictures above, there is a local DNS server, the server is usually supplied with network operators, our PC request DNS are generally represented by it, and it also provides the capability of the DNS cache, you can cache all information in the DNS response, so that we can effectively shorten the time delay, improve the performance. Of course, the cache is not permanent, and the cache information will be lost after the expiration. The specific cache policy is determined by the DNS server provided by the carrier.
The problem
The traditional DNS resolution scheme has some disadvantages
1. The CARRIER’S DNS server is faulty
This is often the case where users in one area fail all network requests, while users in other areas have no problem.
2. Domain name hijacking
This refers to LocalDNS hijacking. An attacker can modify the carrier’s DNS cache or directly attack the carrier’s DNS server to modify the returned response content, so that the domain name can maliciously point to other IP addresses.
3. Inaccurate
LocalDNS scheduling is not always based on the nearest principle. Some small carriers do not have a DNS server, so they directly call the DNS server of other carriers and transfer data across networks. For example, when a mobile carrier dispatches the IP address of the carrier on the user side, the access is slow or even restricted.
HttpDns
The HTTPDNS uses THE HTTP protocol to resolve domain names instead of the UDP-based DNS protocol. Domain name resolution requests are directly sent to the HTTPDNS server, bypassing the carrier’s Local DNS and avoiding domain name hijacking and inaccurate scheduling problems caused by the Local DNS.
reference
The Method of Computer Network Self-direction
Android Network optimization, DNS optimization using HTTPDNS, from principle to OkHttp