ARP stands for Address Resolution protocol. It is used to get the Mac address of the required device using the corresponding IP address. In order for a device to communicate with another device it has know both the IP address and the MAC address.
Usually, the IP address is know and is passed down from the upper layers. In order for the data to be sent of out the port/NIC we need MAC address of the destination host ( if both the device are in same LAN segment) or MAC address the next hop device( if both the device are in different LAN segment.
All L3 Network devices maintain something called “ARP CACHE” table. This maintains the Mac address to the IP address mapping. Before the L2 header is constructed, the device checks the ARP cache table whether the mac address for interested IP address is already present.
- If present, then the device can construct the frame header and feed in the mac address which it got from arp table into the “destination MAC address field ” of the frame and send the frame out.
- If not present, then device has to resolve the mac address for the destination device before it can construct the frame. This is were the ARP protocol comes into play.
Note: If the ARP resolution fails ( Meaning the MAC address mapping for the required IP address is not found), then the actual data can never be sent out of the device. it will be dropped by the L2 layer of the device itself.
Arp process:
Device sends a L2 broadcast frame with destination MAC “FF:FF:FF:FF:FF:FF” in the frame header to all the device in the segment to find the mac address of required IP address. The device which owns the specific IP address reply the MAC address with an ARP Reply.
For example – Consider below scenario:
Device A with IP address 10.1.1.1 and MAC address 00:AA:00:00:00:00 wants to communicate with Device B with IP address 10.1.1.2 and mac address 00:BB:00:00:00:00
Assume “Device A” does not know the mac address of “Device B”. Hence it has to send of a ARP request to find the mac address.
Below is the ARP request process between “Device A” and “Device B”
Arp request sent by Device A:
ARP Reply sent by Device B:
As you can see, The ARP request is a L2 broadcast frame and Arp reply is Unicast frame.
Since the ARP request is a L2 broadcast frame, all the devices in the LAN segment gets the ARP request. And since its sent to L2 broadcast address as destination, all the device in the LAN Segments ends up processing the L2 header and looks into the next ARP header. All the devices looks at the “Target IP address” field of the ARP header and only the matching device will process it. (In this case – Device B with IP address “10.1.1.2” ) All other devices which does not match the IP address simply discards the frame.
Once the ARP reply is received by Device A, it updates the ARP cache and constructs the actual Data packet and sends it out to Device B.