Skip to content

3.3 ARP

1. ARP (Address Resolution Protocol)

Play

ARP Overview

ARP (Address Resolution Protocol) operates at Layer 2 (Data Link Layer) of the OSI model, but it serves as a bridge between Layer 2 (Data Link Layer) and Layer 3 (Network Layer). Here’s a detailed explanation:

1.1 ARP in the OSI Model

  1. Layer 2 (Data Link Layer):

    • ARP is primarily associated with Layer 2 because it deals with MAC addresses, which are Layer 2 addresses.
    • ARP frames are encapsulated in Ethernet frames (Layer 2) for transmission over the network.
  2. Layer 3 (Network Layer):

    • ARP is used to resolve IP addresses (Layer 3) to MAC addresses (Layer 2).
    • It is a critical part of the communication process between devices at the network layer.

1.2 Purpose of ARP

  • ARP is used to map a known IP address (Layer 3) to an unknown MAC address (Layer 2).
  • This mapping is necessary because devices communicate using MAC addresses at the data link layer, but they use IP addresses at the network layer.

1.3 How ARP Works

  1. ARP Request:

    • When a device wants to send data to another device on the same local network, it first checks its ARP cache (a table that stores IP-to-MAC mappings).
    • If the MAC address for the destination IP address is not found in the ARP cache, the device sends an ARP broadcast request to all devices on the local network, asking, “Who has this IP address?”
  2. ARP Reply:

    • The device with the requested IP address responds with an ARP reply, providing its MAC address.
    • The requesting device updates its ARP cache with the new IP-to-MAC mapping.
  3. Communication:

    • Once the MAC address is known, the device can encapsulate the data in an Ethernet frame and send it to the destination.

1.4 ARP Packet Structure

An ARP packet includes the following fields:

  • Hardware Type: Type of hardware (e.g., Ethernet).
  • Protocol Type: Type of protocol (e.g., IPv4).
  • Hardware Address Length: Length of the MAC address (6 bytes for Ethernet).
  • Protocol Address Length: Length of the IP address (4 bytes for IPv4).
  • Operation: Specifies whether the packet is an ARP request or reply.
  • Sender Hardware Address: MAC address of the sender.
  • Sender Protocol Address: IP address of the sender.
  • Target Hardware Address: MAC address of the target (initially unknown in requests).
  • Target Protocol Address: IP address of the target.

1.5 ARP Cache

  • Devices maintain an ARP cache (or ARP table) to store IP-to-MAC mappings.
  • Entries in the ARP cache have a limited lifetime (usually a few minutes) to ensure the cache stays up-to-date.

1.6 Example of ARP in Action

  1. Scenario:

    • PC1 (IP: 192.168.1.10, MAC: 00:11:22:33:44:55) wants to send data to PC2 (IP: 192.168.1.20, MAC: unknown).
  2. ARP Request:

    • PC1 checks its ARP cache for the MAC address of 192.168.1.20. If not found, it sends an ARP broadcast: “Who has 192.168.1.20?”
  3. ARP Reply:

    • PC2 responds: “I have 192.168.1.20, and my MAC address is 00:AA:BB:CC:DD:EE.”
  4. Communication:

    • PC1 updates its ARP cache and sends the data to PC2 using the MAC address 00:AA:BB:CC:DD:EE.

1.7 Reverse ARP (RARP)

  • RARP is the opposite of ARP. It is used to resolve a MAC address to an IP address.
  • RARP is rarely used today, as it has been replaced by more advanced protocols like DHCP.

1.8 Gratuitous ARP

  • A special type of ARP used to update the ARP caches of other devices.
  • Example: When a device changes its IP address, it sends a gratuitous ARP to inform other devices of the change.