“Can’t computers communicate with each other using only IP addresses?”

01 preface


When we search a certain website on the Internet, such as Google search, we usually enter WWW. Google.com to search, but in fact we need to get its IP address to connect with the host. This process benefits from DNS domain name resolution, through a corresponding relationship between domain name and IP address can get the target IP address, so as to communicate. But the IP address is not enough, but also need a MAC address to complete the communication, and to get the MAC address also benefits from the ARP address resolution protocol, the whole process is everyone’s mutual cooperation, next to say about the middle exactly how to work.

02 What is DNS


Usually we don’t remember the IP address of a website because it’s too hard to remember. DNS is the domain name resolution system, which has a database of host names and IP addresses. Its function is to convert the domain name into IP address, IP address is the unique host name on the network, used for host identification. So how does it resolve our IP address? In general, he is likely to go through the following steps:

  • The IP address was cached when looking up the browser
  • Check whether the operating system caches the IP address
  • Check whether the router caches the IP address
  • Cache IP addresses for searching service operators
  • Find the IP address corresponding to the DNS server

Because network resources are precious, if the means of caching are not passed in the middle, the network may be blocked or the network can not withstand the huge requests in the middle, so it must be cached. However, it is not always cached. After a certain period of time, the record will disappear and be rerequested and cached.

If the browser and router are not available, the general service operator is China Telecom or China Mobile, to find whether the IP address cache, if the final or not, you can only go to the root domain name server search, this time can be found. When the IP address is returned, the process is cached by browsers, operating systems, carriers, etc., so that the next search won’t have to take such a long detour.

03 What is a domain name


A domain name is a hierarchical name that identifies a host name and an organization name. – diagram to TCP/IP

Domain names have a hierarchical structure. For example, some domain names have a suffix of. Com/.cn/.org, which represents different organizations and facilitates domain name management. The hierarchy of domain names is similar to the inverted tree structure, with the top level representing the root domain name, followed by the second level domain name, third level domain name, and so on.

Pictures from the network (delete)

It is clear from the above chart that a top-level domain has a national top-level domain, for example, China’s top-level domain ends in.cn, while Britain’s ends in.uk. And you can see that some educational websites end in.edu, some college websites end in.edu.

04 What is ARP


ARP is an address resolution protocol. You can use the DNS domain name system to find the IP address of the host. However, an IP address is not enough because the underlying data link layer searches for the MAC address of each IP address during actual communication. The ARP protocol is used to transfer IP addresses to MAC addresses.

Working mechanism

We can take the example of host A sending data to host B to see how the intermediate process works.

To obtain the MAC address of host B, host A broadcasts an ARP request packet containing the destination IP address on the current data link. All hosts on the same link receive this request packet. Then, each host compares its IP address with its own IP address. If it matches its OWN IP address, the host receives this request packet and sends a response packet containing its MAC address.

In addition, the ARP request packet also contains host A’s MAC address. After obtaining the MAC address of user B, the system also caches the MAC address to prevent the next request packet from being sent, saving traffic. Such a TABLE that corresponds to MAC addresses and IP addresses is the ARP table. The MAC address cache also has a certain period of time. After the time is exceeded, the content will be cleared and a new request will be made.

Relationship between IP address and MAC address

In fact, FOR a period of time I have not quite understood why IP after the MAC to communicate? Isn’t that superfluous?

First of all, there is a very important difference to understand. IP addresses change. Once you turn off and restart your computer, the IP may change, but MAC addresses are different. It’s the same as our ID number, but your address may change after you move.

A large proportion of network traffic is not on the same network, so the data has to pass through many routers to find your host. For example, the address we write for online shopping is IP address. We all know the distribution mechanism of express delivery, which is distributed layer by layer through province/city/district, and will eventually find your location. But other than that, you need to know what your name is to get it in your hand, and that’s what the MAC address is for.

RARP

ARP is used to find the IP address corresponding to the MAC address. So what does this protocol do? We know that the function of DHCP is to dynamically allocate an IP address to the current host. We can set it by ourselves through the computer. If you do not set it, DHCP will assign an IP address to you. For example, when our printer is connected to the Internet, we will use this protocol. When we plug in the power, we will send a message “my MAC address is XXX, what is my CORRESPONDING IP address?” Request information.

The corresponding RARP server registers your MAC address and assigns you an IP address.

05 summary


Through the above resolution, we know the relationship between the DNS domain name resolution system and IP address, through the IP address we can use the ARP address resolution protocol to find the MAC address. By matching the IP address with the MAC address, we can accurately communicate with the target host. Here we know ARP is a broadcast function, broadcast we will use UDP protocol (TCP does not support broadcast), in fact, there is a certain connection between various protocols.

We also know the hierarchical structure of domain names, which are uniformly assigned by top-level domains and have a certain management structure. Moreover, we generally cannot apply for domain names casually. For example, individuals cannot apply for educational or government domain names.