The Importance of Using the Address Routing Protocol (ARP)
When a device wants to communicate with another device on the same network, it needs to know the physical address of that device. However, the device only knows the network address of the other device, which is not enough to communicate at the data link layer, so the source device must learn that missing information somehow.
There are two options to learn the MAC address of the destination host: manually or dynamically. The manual configuration is a straightforward process but not scalable when you have many devices in your network. This is because you must manually create a mapping for each device’s MAC and IP address.
The other, better option is to use dynamic learning. This can easily be achieved with the help of ARP, a Layer 2 protocol used in networks to map an IP address to a MAC address of other devices on the network. The learning process involves three main steps:
Step 1 - Broadcast Message
The sending device broadcasts an ARP request message to all devices on the network to find the physical address of the destination host. The message contains the IP address of the destination device that the sending device wants to communicate with.
Step 2 - Reply Message
All devices on the network receive the ARP request message, but only the device with the matching IP address sends an ARP reply message back to the sending computer. The reply message contains the MAC address of the destination device mapped to its IP address.
Step 3 - Store Physical Address
The sending device receives the ARP reply message and stores the physical address in its ARP cache. The ARP cache is a table that contains the mappings of IP addresses to MAC addresses that the device has learned through the ARP process.
The sending device can now use the learned MAC address to communicate directly with the destination device on the network.
Important: Dynamically learned mappings are not permanently saved in the ARP table but expire after some time. The default expiration time for Cisco devices is 4 hours. However, other systems have different timeouts.
By implementing a timeout, the ARP table is prevented from holding information for devices not active in the network anymore. However, when the device intends to send data again to a device for which the MAC address is no longer available, the ARP process regenerates the entry in the ARP table.
A Practical Example of the ARP Learning Process
As you can see from the image below, the computer (PC1) wants to print something. However, it does not know the printer’s MAC address. An ARP request message is sent, which is received by any device in the local network, including the printer.
Because the printer recognizes its IP address in the ARP request message, it replies with an ARP reply message that contains the mapping of its IP and MAC addresses. Upon receipt, both parameters are included in the ARP table of PC1.
Now that the host has the previously missing parameter, it can create a Layer 2 frame and forward the data to the printer.
Note: The printer will not always be in the same network as the host. In such a case, the host needs to use a default gateway to send data to the printer.