ARP protocol usage
Because IP packets are sent in Ethernet packets, we must know two addresses at the same time, one is the MAC address of the other and the other is the IP address of the other. Generally, the IP address of the other party is known, but we do not know its MAC address. Therefore, we need a mechanism to obtain the MAC address from the IP address. There are two cases. In the first case, if the two hosts are not in the same subnet, there is actually no way to get the MAC address of the other host, you can only send data packets to the "gateway" at the two sub-network connections for the gateway to process. In the second case, if the two hosts are in the same subnet, we can use ARP to obtain the MAC address of the other host. ARP also sends a data packet (including the Ethernet data packet), which contains the IP address of the host to be queried. In the MAC address column of the other host, this parameter is FF: FF: FF, indicating a "broadcast" address. Each host in its sub-network receives this packet, extracts the IP address from it, and compares it with its own IP address. If the two are the same, send a response and report the MAC address to the other party. Otherwise, the packet will be discarded. In short, with the ARP protocol, we can get the MAC address of the host in the same subnetwork and send the packets to any host.