Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 6

ARP: Connecting IPs to MACs

Recommended resources

Hello! Welcome to the sixth lesson in our module on Networking Fundamentals.

In our last lesson, we explored subnetting—the process of dividing a large network into smaller, more manageable subnetworks. You learned that a device uses its IP address and subnet mask to determine if a destination is on the local network or a remote one. This distinction is crucial for what comes next.

Today, we'll answer the question: Once a device knows another machine is on the same local network, how does it actually send data to it? This brings us to our learning outcome: Explain the function of the Address Resolution Protocol (ARP) in linking IP addresses to MAC addresses.

We'll uncover the fundamental problem that ARP solves, walk through its elegant request-and-reply mechanism, and, importantly for your goals, examine the security weaknesses inherent in its design.

The Two-Address Problem

Communication on a network involves addresses at different layers of the OSI model.

  • At Layer 3 (the Network Layer), we use logical addresses: IP addresses. These are used to route packets across different networks, from the source all the way to the destination network.
  • At Layer 2 (the Data Link Layer), we use physical addresses: MAC addresses. These are used for the final delivery of a frame between devices on the same local network segment (like devices connected to the same switch).

Here's the problem: Your computer might know it wants to send a packet to 192.168.1.10, but the Ethernet switch it's connected to only understands MAC addresses. To create the final Ethernet frame, your computer needs to find the MAC address that corresponds to 192.168.1.10. How does it bridge this gap between a known IP address and an unknown MAC address?

This is precisely the job of the Address Resolution Protocol (ARP).

Let's start with a video that clearly sets up this scenario.

ARP: Mapping between IP and Ethernet | Networking tutorial (9 of 13)

The video 'ARP: Mapping between IP and Ethernet' by Ben Eater explains why direct communication using only MAC or IP addresses isn't sufficient and how devices on a local network need a way to find each other's physical hardware addresses.

Watch the video from 00:00 to 02:37, and then from 05:06 to 05:36. Focus on understanding why a sending computer can't just use the final destination's MAC address when it's on a different network, and how that leads to the need for a protocol like ARP to find the MAC address of the local gateway router.

As the video explains, your computer needs to find the MAC address of the next hop on the local network.

  • If the final destination is on the same subnet, the next hop is the destination device itself.
  • If the final destination is on a remote network, the next hop is the default gateway (the local router interface).

In both cases, ARP is used to find that local MAC address.


The ARP Process: A Conversation on the Network

ARP works through a simple, two-step "question and answer" process that happens on the local network.

  1. ARP Request (The Question): The requesting computer sends a special message, an ARP Request, across the entire local network. This is a broadcast. You can think of it as someone shouting in a room: "I'm looking for the device using IP address 192.168.1.10. Can you please tell me your MAC address? By the way, my IP is 192.168.1.5 and my MAC is AA:BB:CC:11:22:33."

  2. ARP Reply (The Answer): Every device on the local network receives and hears this broadcast. However, only the one device that actually owns the IP address 192.168.1.10 will formulate a response. All other devices simply ignore the request. The target device sends an ARP Reply directly back to the original requester. This is a unicast message. It's like a person in the room responding directly to the one who asked: "I have IP address 192.168.1.10, and my MAC address is DD:EE:FF:44:55:66."

Once the original computer receives this reply, it now has the mapping it needs and can send its data.

This image perfectly illustrates the two steps:

ARP Request and Reply Process
This diagram shows the two main phases of ARP. Part (a) shows System A broadcasting an ARP request to all devices on the network to find the MAC address for a specific IP. Part (b) shows System B, which owns that IP, sending a unicast ARP reply directly back to System A with its MAC address.

To see this process animated with a detailed example, please watch the following segment.

Address Resolution Protocol (ARP) - Explained with example | Computer network | TechTerms

The video 'Address Resolution Protocol (ARP) - Explained with example' provides a clear, animated walkthrough of the ARP request being broadcast and the subsequent reply.

Watch from 06:05 to 08:53. Pay close attention to how the switch handles the broadcast request and how the target device constructs and sends the unicast reply.


The ARP Cache: Remembering Conversations

Broadcasting an ARP request for every single IP packet would be incredibly inefficient and create a lot of unnecessary network noise. To prevent this, operating systems maintain a temporary storage area called the ARP cache (or ARP table).

When a device receives an ARP reply, it stores the IP-to-MAC address mapping in this cache.

  • Before sending a packet, a device first checks its ARP cache.
  • If a valid entry for the destination IP exists, it uses the cached MAC address and sends the data immediately. No ARP broadcast is needed.
  • If no entry exists, then it initiates the ARP request/reply process and adds the new mapping to its cache.

These cache entries are temporary and will be cleared after a set period (a timeout) to ensure the information doesn't become stale if a device's IP or MAC address changes.


Peeking Inside: The ARP Packet Structure

Let's briefly look at the fields inside an ARP message. Understanding this structure is crucial for analyzing network traffic and grasping how ARP-based attacks work.

Address Resolution Protocol - Wikipedia

The Wikipedia article on 'Address Resolution Protocol' provides a very clear table detailing the fields of an ARP packet for IPv4 over Ethernet.

Please read the section 'Packet structure'. Focus on the table and the descriptions of the key fields: Hardware Type, Protocol Type, Operation (request vs. reply), and the four address fields (Sender and Target Hardware/Protocol addresses).

The key fields to remember are:

  • Operation Code: A single field that specifies if the packet is a request (1) or a reply (2).
  • Sender Hardware Address (SHA): The MAC address of the sender.
  • Sender Protocol Address (SPA): The IP address of the sender.
  • Target Hardware Address (THA): The MAC address of the intended receiver. In a request, this is left blank (or set to all zeros) because it's the information being sought.
  • Target Protocol Address (TPA): The IP address of the intended receiver.

Security Weakness: ARP Spoofing

Here we arrive at a critical point for your journey into ethical hacking. ARP was designed in an era when networks were considered trusted environments. As such, ARP is a stateless and trusting protocol. It has no mechanism to verify that an ARP reply is legitimate or comes from the actual owner of an IP address.

This opens the door to a common and powerful attack: ARP Spoofing (also known as ARP Cache Poisoning).

An attacker on the local network can exploit this trust by sending forged ARP replies. For example, an attacker can send an ARP reply to your computer that falsely claims: "I have the router's IP address, and my MAC address is [attacker's MAC address]."

Your computer, trusting the reply, will update its ARP cache, creating an entry that maps the router's IP to the attacker's MAC address. From that point on, all the traffic you intend to send to the internet will be sent to the attacker's machine first. This places the attacker in a Man-in-the-Middle (MitM) position, allowing them to intercept, read, or modify all of your outbound traffic.

How Address Resolution Protocol (ARP) Works? - GeeksforGeeks

The article from GeeksforGeeks, 'How Address Resolution Protocol (ARP) Works?', has an excellent section on the security implications.

Read the section titled 'ARP Spoofing and ARP Cache Poisoning'. This will connect the theoretical function of ARP directly to its application in network attacks like Man-in-the-Middle.

Understanding this vulnerability is fundamental. Many tools in Kali Linux are designed to either perform or detect ARP spoofing attacks.


Conclusion

In this lesson, we demystified the crucial link between the Network and Data Link layers. You now understand how devices on a local network use ARP to resolve logical IP addresses into physical MAC addresses, a necessary step for any local communication.

Key Takeaways:

  • Function: ARP resolves a known Layer 3 IP address to an unknown Layer 2 MAC address on a local network segment.
  • Process: It uses a broadcast ARP Request to ask "who has this IP?" and a unicast ARP Reply to provide the corresponding MAC address.
  • Efficiency: Devices maintain an ARP cache to store recent mappings, avoiding excessive broadcast traffic.
  • Vulnerability: ARP is inherently insecure. Its lack of authentication makes it vulnerable to ARP spoofing, which can enable Man-in-the-Middle attacks.

In our next lesson, we will move one step up the OSI model to Layer 4. Once a packet arrives at the correct machine, how does that machine's operating system know which application (e.g., web browser, email client) to deliver it to? We will answer this by exploring the role of ports in network communication.