ARP (Address Resolution Protocol) is a Layer2 protocol that is used to translate IP addresses (layer 3 in OSI model ) to MAC addresses (layer 2 in OSI model ), and is used when two hosts on a Local Area Ethernet Network want to communicate with each other.
Of course ARP is used in other Layer 2 networks such as ATM for example, but the main usage of ARP is on Ethernet Networks.
The first time Host A wants to contact Host B, Host A sends an ARP Request (using a broadcast packet) on the LAN. The ARP packet basically asks the following “I have the IP address for Host B and I want to know the MAC address of Host B”.
Host B sees this broadcast packet and replies to Host A with an ARP Reply packet containing host B’s MAC address.
Host A now saves this MAC address/IP address combination in its ARP cache and begins to communicate with host B.
This communication happens with Layer2 MAC Addresses because the two hosts are on the same Layer 2 network.
To display the contents of a host’s ARP cache (table), use “arp-a” on a Windows platform, “arp” on a UNIX platform, and “show arp” on a Cisco IOS platform.
Now, what if the destination host is not on the same Layer 3 subnet of the origin host? In this case, the default gateway router of the origin host will reply to the ARP request and give its own MAC address so the origin host will send its packets to the default gateway in order to reach the destination host.
The default gateway will take the packets and using Layer 3 routing will send the packets to the correct interface in order to reach the destination host (of course the packets can traverse several routers before reaching the final destination).