The relationship and principle analysis of DNS and ARP

The relationship and principle analysis of DNS and ARP

"Can't communication between computers only be done by IP address?"

Insert picture description here

01 Preface


When we search for a website on the Internet, such as Google search, we usually enter www.google.com to query, but in fact we need to get its IP address to connect with the host. This process benefits from the DNS domain name resolution, and the target IP address can be obtained through a correspondence between the domain name and the IP address to communicate. But with an IP address is not enough, you need a MAC address to complete the communication, and to get the MAC address also thanks to the ARP address resolution protocol, the entire process is mutual cooperation between everyone, let's talk about what is in the middle. work.

Insert picture description here

02 What is DNS


Usually we remember that a website will not remember his IP address, because it is too difficult to remember. DNS is a domain name resolution system, which has a database of host names and IP addresses. Its function is to convert the domain name into an IP address, and the IP address is the only determined host name on the network for the identification of the host. So how does it resolve our IP address? In general, he may go through the following steps:

  • The IP address was cached when looking up the browser
  • Find out if the operating system caches the IP address
  • Find out if the router caches the IP address
  • Cache IP address when looking for service operator
  • Find the IP address corresponding to the domain name server

Because network resources are more valuable, if you don't pass the caching method halfway, it may cause network congestion or the network cannot afford huge requests in the middle, so you must cache it. However, there is not always a cache. After a certain time, the record will disappear, re-request and cache.

If there are no browsers or routers, the general service operator is China Telecom or China Mobile to find out whether the IP address is cached. If it does not exist in the end, you can only go to the root domain name server to find it. This time you will be able to find it. When the IP address is returned, the intermediate process will be cached by the browser, operating system, operator, etc., so the next time you search for it, you won't go so far.

Insert picture description here

03 What is a domain name


The domain name refers to a name with a hierarchical structure in order to identify the host name and organization name. ——Illustrated TCP / IP

Domain names have a hierarchical structure. For example, some domain names have a suffix of .com / .cn / .org, etc., which represent different organizations and facilitate the management of domain names. The layering of domain names is somewhat similar to an inverted tree structure. The top level represents the root domain name. Below are the second-level domain names and third-level domain names.

Insert picture description here
Pictures from the Internet (invasion and deletion)

It can be clearly seen from the above picture that the top-level domain name has a national top-level domain name. For example, China ends with .cn, and the United Kingdom ends with .uk. Below we can see that some education websites all end with .edu, and the university's official website ends with these.

04 What is ARP


ARP is an address resolution protocol. Above, we know that the IP address of the corresponding host can be found through the DNS domain name system, but having an IP address is not enough, because the underlying data link layer will find each IP address during actual communication. Corresponding MAC address. And from IP address to MAC address depends on ARP protocol.

Working Mechanism

We can take host A to send data to host B as an example to see how the intermediate process works.

Insert picture description here

In order to obtain the MAC address of host B, host A will first broadcast an ARP request packet on the current data link, which contains the target IP address. Because the hosts on the same link will receive this request packet, then each host will be compared with its own IP address according to the IP address, if it matches with itself, it will receive this request packet, and then send a response packet, It contains its own MAC address.

In addition to this, the ARP request packet also contains the MAC address of host A. When the MAC address of B is obtained, it will be cached to prevent the next request from sending the request packet again, saving traffic. Such a table corresponding to the MAC address and the IP address is the ARP table, and the MAC address cache also has a certain time. After the time is over, the content will be cleared, and then re-requested.

Relationship between IP address and MAC address

In fact, for a while, I haven't quite understood why MAC is needed to communicate after having an IP? Isn't this superfluous?

First of all, we must understand a very important difference. The IP address will change. Once you shut down and restart, the IP may be different, but the MAC address is different. It will always be the same and will not change. It is the same as our ID number, but your address may change after you move.

A large part of network communication is not on the same network, so data will go through many routers to find your host. For example, the address of our online shopping is the IP address. We all know the delivery mechanism of express delivery. After being distributed layer by layer in provinces / cities / districts, you will eventually find your location. But except for this position, you have to know what your name will be accurately assigned to your hand, this is the role of the MAC address.

Insert picture description here

RARP

This is actually the opposite of ARP. The function is to find out the IP address corresponding to the MAC address. So what's the use of this agreement? We know that the role of DHCP is to dynamically assign an IP address to the current host. We can set it through the computer. If it is not set, DHCP will assign an IP address to you. For example, this protocol is used when our printers are connected to the network. When we plug in the power supply, we will send a request message "My MAC address is xxx, what is my corresponding IP address?"

Then the corresponding RARP server will register your MAC address on it and assign an IP address to you.

Insert picture description here

05 Summary


Through the above analysis, we know the relationship between the DNS domain name resolution system and the IP address. Through the IP address, we can use the ARP address resolution protocol to find the MAC address. Through the cooperation of IP address and MAC address, we will accurately communicate with the target host. Here we know that ARP is a broadcast function. When broadcasting, we will use the UDP protocol (TCP does not support broadcasting). In fact, there are certain connections between various protocols.

We also know that the hierarchical structure between domain names is uniformly allocated by top-level domain names and has a certain management structure, and we generally cannot apply for domain names casually. For example, individuals cannot apply for education or government domain names.

Insert picture description here

Published 57 original articles · won praise 6 · views 6419

Guess you like

Origin blog.csdn.net/weixin_42724176/article/details/104885191