Do you really understand the DNS protocol that is used every day at work?

♥ Foreword

When we often visit some URLs, we enter an address similar to www.baidu.com into the browser. Then enter this address into the browser ---> Baidu server returns us the Baidu page. What is the process in between? What kind of thing?

With this question in mind, let’s analyze the process together.

1. The relationship between domain name and IP

First of all, addresses like 'www.baidu.com' and 'www.sina.com.cn' are collectively called domain names. So, after using the domain name to access, can the request directly reach the corresponding server?

no!

In this process, the domain name needs to be converted into an IP address. Only by searching through the IP address can the location of the server be found and the server can receive the request.

Why do we need to perform this conversion operation between domain name and IP? Let’s answer two questions:

  1. So why don't we communicate directly using IP addresses?

    Because IP addresses are inconvenient for users to remember, domain names are more convenient for users to remember and use. For example, www.baidu.com is the domain name of Baidu; www.sina.com.cn is the domain name of Sina, which is very easy to understand and remember;

  2. Then why not just use the domain name to find the server?

This is because the length of the domain name is not fixed, which is not convenient for computers to process; and the IP address is of fixed length. If it is an IPv4 address, it is 32 bits, and the IPv6 address is 128 bits. Fixed length is more convenient for computers to process.

Therefore, the summary is that the IP address is for the host, while the domain name is for the user. So we need to convert domain names and IP addresses to each other.

2. Convert domain name to IP address

hosts file

In the beginning, people used the computer's hosts file to convert domain names and IPs.

There is a host file under the path C:\Windows\System32\drivers\etc on our computer, which can save the corresponding relationship between domain names and IPs, as shown in the following figure:

The line framed in the picture maps the IP address 120.24.89.47 to the domain name www.tricy1.com. After the configuration is completed, even if the domain name www.tricy1.com is not a real registered domain name, you can still access the domain name www.tricy1.com on this computer and you can access the website corresponding to this IP address (Lemon Class test send forum).

Initially, the hosts file is managed through the Internet Information Center. If a new computer wants to connect to the network, or a certain computing IP changes, you need to apply to the information center to change the hosts file. Other computers also require regular updates before they can access the Internet. But this is too much trouble. For easier operation, the DNS protocol emerged.

DNS protocol

DNS protocol, the full name of Domain Name System, is an application layer protocol, which is built on UDP or TCP protocol and uses port 53 by default.

The client communicates through the UDP protocol by default, but because the WAN is not suitable for transmitting large UDP data packets, it is stipulated that when the length of the message exceeds 512 bytes, it should be converted to use the TCP protocol for data transmission. Therefore, the DNS protocol is one of the few application layer protocols that can use both the UDP protocol and the TCP protocol as the underlying protocol.

The function of this protocol is to convert human-readable domain names (eg, www.qq.com) into machine-readable IP addresses (eg, 119.147.15.13).

If you want to learn automated testing, I recommend a set of videos to you. This video can be said to be the number one automated testing tutorial on the entire network played by Bilibili. The number of people online at the same time has reached 1,000, and there are also notes that can be collected and communicated with various channels. Master technical communication: 798478386    

[Updated] A complete collection of the most detailed practical tutorials on Python interface automation testing taught by Bilibili (the latest practical version)_bilibili_bilibili [Updated] A complete collection of the most detailed practical tutorials on Python interface automated testing taught by Bilibili (practical version) The latest version) has a total of 200 videos, including: 1. Why interface automation should be done for interface automation, 2. Overall view of request for interface automation, 3. Interface practice for interface automation, etc. For more exciting videos from UP master, please follow the UP account . icon-default.png?t=N7T8https://www.bilibili.com/video/BV17p4y1B77x/?spm_id_from=333.337

picture

Domain name hierarchical structure:

As you can see in the picture above, the domain names are separated by dots. What do the dots separated by each point represent?

We need to understand that the domain name is a hierarchical structure, and the domain name server is also a corresponding hierarchical structure, which are the root domain name, the top-level domain name system, the second-level domain name system, the third-level domain name system, etc., as shown in the following figure:

picture

There are 13 root servers in the world. The Chinese names of these 13 root domain name servers are "A" to "M", 10 of which are set up in the United States, and the other three are set up in the United Kingdom, Sweden, and Japan. One main root server is placed in the United States, and the remaining 12 are auxiliary root servers.

For example, the hierarchical structure of the domain name www.baidu.com is as follows:

com: top-level domain name. Indicates that this is a corporate domain name.

baidu: Second-level domain name, referring to the company name.

www: Internet Protocol (World Wide Web)

Domain names generally cannot exceed level 5. The levels of domains become higher from left to right, and higher-level domains include lower-level domains. The domain name is unique in the entire Internet. When the high-level subdomain name is the same, the low-level subdomain name is not allowed to be repeated.

With the domain name structure, one more thing is needed to resolve domain names, and that is a domain name server.

Domain names need to be resolved by domain name servers all over the world. Domain name servers are actually hosts equipped with domain name systems.

DNS resolution process

picture

As shown above, let's analyze the process of DNS resolution:

The user wants to access the Baidu server through the client browser - the domain name is www.baidu.com:

  1. When the user enters the domain name www.baidu.com in the browser, the browser cache will be searched first by default to see if the cache contains the IP address corresponding to the domain name.

  2. When it cannot be found in the browser, it will check whether there is a corresponding IP address in the Hosts file in the system.

  3. If there is no mapping of this domain name in hosts, search the local DNS server;

  4. If not, search the root domain name server through the DNS server; the root domain name service returns the IP address of the top-level domain name server that can be queried;

  5. The top-level domain name server returns a DNS response message;

  6. After the host receives the response message, it can access the server normally; the result will be saved for next use.


The query methods of the DNS protocol are divided into the following two types:


Recursive query : The machine sends a query request to the local domain name server and waits for the final result. If the local domain name server cannot resolve it, it will query other domain name servers as a DNS client until it gets the final IP address and tells this machine

picture

Iterative query : The local domain name server queries the root domain name server. The root domain name server tells it where to query next, and then it checks again. Each time it queries each server as a client.

picture

In layman's terms, recursion is to hand over a thing to someone else. If the thing is not finished, even if it has been done a lot, don't tell me the result. What I want is your final result, not the intermediate result; if you haven't After you finish it, please find someone else to finish it.

Iteration is when I give you a task, tell me how much you have done, and then I will do the rest.

 

Guess you like

Origin blog.csdn.net/m0_73409141/article/details/132791689