Address Resolution Protocol (ARP) is a dynamic mapping protocol that maps the IP address of a computer to it’s MAC address. ARP maps the 32-bit IPv4 address of the receiver to 48-bit MAC address of the receiver. The Address Resolution Protocol is a Network Layer protocol. There also exists a reverse ARP protocol (RARP) that translates MAC address to IP address.
In this section, we will discuss the cases when the ARP services can be used. We will also discuss the working of ARP and the packet format of ARP in brief.
Content: Address Resolution Protocol
When the services of ARP are used?
If a host wants to send a data packet to another host in a global network, it must have the IP address of the corresponding receiver. But, as we know the packet has to pass through several physical networks before reaching the corresponding receiver. To pass through these physical networks, the sending host requires the physical MAC address of every hop in between sender and receiver & also MAC address of the receiver to deliver the packet.
This service of ‘mapping’ the ‘IP address’ of the receiver to the ‘MAC address’ of the receiver is done by ‘Address Resolution Protocol’ (ARP).
Below are the four scenarios where the services of ARP protocol are needed:
Case 1: A host has a data packet to send it to another host in the ‘same network’ as that of sender host. In this scenario, the IP address of the receiver host needs to mapped with the MAC address of the receiver host. So, sender host will send ARP packet to the receiver host requesting for its Mac address.
Case 2: A host has a data packet to send it to another host which is in a ‘different network’ as that of the host. In this scenario, the sender host scans its routing table and discover the IP address of the ‘next router (hop)’ in the path of the destination host. If the sender host doesn’t have a routing table, then it searches for the IP address of the ‘default router. So, the sender host will send the ARP packet to the next-hop router to get its MAC address.
Case 3: A router has received a data packet that has to be forwarded to the receiver host which is in ‘another network’. Then the router will search its routing table to find the IP address of the next-hop router in the path. Here, the router that has to forward data packet, send the ARP request to the next router in the path requesting its MAC address.
Case 4: A router has received a data packet that is destined to the host in the ‘same network’ as of router. In this scenario, the router has to send an ARP request packet to the destined host requesting its MAC address.
How Does Address Resolution Protocol (ARP) Work?
Whenever a host has to send a packet to any other host it knows the target hosts IP address. You must be wondering;
How does a sender host know the IP address of destination host?
A host knows the other host by its ‘name’. Like, you know Google by its ‘hostname’ or ‘domain name’ i.e. google.com, you don’t have to worry about its ‘IP address’. It is the ‘DNS server’ who resolve the domain name into the IP address.
So, whenever a host has to send a packet to another host. It only knows the target hosts name. DNS resolves the target hosts name into it’s IP address. Thus, we say whenever a host wants to send a packet to target host it knows its IP address.
Coming back to the ARP, as we have said that a sender knows the receivers IP address. But, the packet has to pass through the physical network so, it requires the physical MAC address of the target host.
The IP protocol asks the ARP protocol to prepare a request packet with senders IP address, senders MAC address, target hosts IP address and the target hosts MAC address field is not filled.
The packet is then passed to the data link layer. Here, the packet is encapsulated inside a frame which has source address as sender’s physical address and destination address as a physical broadcast address.
As the encapsulation packet has broadcast address in the destination address field, it is received by each host in the network. The target host keeps the packet as it identifies its IP address in the ARP packet. The host other than target host rejects the packet.
Now, the target host prepares an ARP reply packet with its physical MAC address. This reply packet is unicast to the sending host.
The sender now receives the ARP reply message and thereby now knows the physical MAC address of target host.
The sender now passes the IP datagram which has the data for target host to the data link layer where it is encapsulated in a frame with sender’s MAC address as a source address and target hosts MAC address as the destination address and this frame is unicast to the destined target host.
Packet Format of ARP
After getting the working of ARP let us discuss the packet format of ARP. The figure below shows the ARP packet format:
Below we have described the fields of ARP packet:
1. Hardware Type: This field describes the type of network. Actually, each network is assigned an integer which defines its type. Like, Ethernet is assigned the type 1. This is a 16-bit field.
2. Protocol Type: This field is of 16-bit and is used for defining the protocol.
3. Hardware Length: This field defines the length of the MAC address in bytes. This is an 8-bit field.
4. Protocol Length: This is also an 8-bit field and it defines the length of IP address in bytes.
5. Operation: This field defines the type of ARP packet i.e. ARP request (1) or ARP reply (2). This is a 16-bit field.
6. Sender Hardware Address: This field defines the MAC address or the hardware address of the sender. This field has a variable length.
7. Sender Protocol Address: This is a variable-length field and it defines the IP address of the sender.
8. Target Hardware Address: This is a variable-length field and it defines the MAC address of the target host.
9. Target Protocol Address: This a variable-length field and it defines the IP address of the target host.
- Address Resolution Protocol is a network layer protocol.
- Knowing the IP address of the target host ARP protocol retrieves the MAC address of the target host.
- ARP maps 32-bit IP address of the target host to 48-bit Mac address of target host.
- ARP request packet is broadcasted in the network. On the other hand, the ARP reply packet is unicast.
So, this was all about the Address Resolution Protocol (ARP) which dynamically maps the IP address to the MAC address. ARP has a reverse protocol i.e. Reverse Address Resolution Protocol (RARP) that maps MAC address to the IP address.