Bài gốc: Unveiling the Secrets of How IP and ARP Work — tác giả BaconYao, lấy qua Notion public API.
Key TakeAway
P.S. Before staring this journey, I recommend you to know the Network Namespace and VETH concepts, feel free to check out my earlier article: 1. Network Namespace and Virtual Ethernet (VETH)Address Resolution Protocol (ARP)
The Concept of ARP
Core Function
The main function of ARP is to solve the following problem: Within the same local area network (LAN), when a device knows the destination’sIP address, how can it obtain the corresponding MAC address in order to transmit packets at the Data Link Layer (Layer 2).
Key Characteristics
-
BroadcastandUnicast: ARP requests are broadcast (sent to all devices on the network), while ARP replies are unicast (sent only to the requester). - Scope of Application: ARP only works within the same subnet (Layer 2 network). Communication across different subnets relies on routers and Proxy ARP.
- Protocol Layering: ARP operates at the Data Link Layer (Layer 2) but serves the IP protocol at the Network Layer (Layer 3).
- Security Issues: ARP lacks authentication mechanisms, making it vulnerable to ARP spoofing attacks, where an attacker can forge MAC addresses to intercept or redirect network traffic.
How It Works
-
ARP Request
-
When Device A wants to communicate with Device B but only knows B’s IP address (e.g., 192.168.1.2), it
broadcastsanARP requestpacket to the local network. -
The request packet includes:
- The sender’s IP and MAC addresses.
- The target IP address (e.g., 192.168.1.2).
-
The target MAC address field is left blank (usually filled with all
zeros).
- This broadcast packet is received by all devices on the same subnet.
-
When Device A wants to communicate with Device B but only knows B’s IP address (e.g., 192.168.1.2), it
-
ARP Reply
-
When Device B receives the ARP request and sees that the target IP matches its own, it sends back an
ARP replypacket. -
The reply contains B’s MAC address and is sent directly to Device A (
unicast). -
Upon receiving the reply, Device A stores the IP-MAC mapping in its
ARP table(ARP cache) for future use.
-
When Device B receives the ARP request and sees that the target IP matches its own, it sends back an
ARP Table
- Every device maintains an ARP table that stores the mappings between resolved IP addresses and their corresponding MAC addresses.
- ARP table entries have a limited lifetime; expired entries are removed and require a new ARP request to be sent.
Experiment
Setting Up the Experiment Environment – Network Namespace
Creating Namespaces and VETH
In our host system, we will create two isolated network namespaces and connect them using a pair of virtual Ethernet (veth) interfaces. This setup simulates two virtual hosts on the same local network.Assigning IP Addresses to VETH Interfaces

Using the following commands, we assign an IP address to the
eth0 interface in each network namespace, as shown in the figure on the left.Commands
Commands
實驗 一: 查看 ARP Table

Here’s a breakdown of the steps shown in the left diagram:
-
Check the ARP table in
ns1:- Initially, you’ll observe that there are no entries in the ARP table.
-
Ping
ns2fromns1:- This tests whether
ns1can communicate withns2.
- This tests whether
-
Check the
ARP tablesin bothns1andns2again:-
You will notice that
ns1’s ARP table now contains a new entry with the following details:-
IP Address:
10.22.33.55- This is the IPv4 address of the neighboring device, indicating your system recognizes that this IP is on the same network.
-
Device:
dev eth0- This means the system uses the
eth0interface to communicate with10.22.33.55.
- This means the system uses the
-
Link Layer Address (MAC Address):
lladdr 8a:0d:df:ba:d4:1f- This is the MAC address associated with the IP
10.22.33.55, representing the physical address of the neighbor device.
- This is the MAC address associated with the IP
-
IP Address:
-
You will notice that
Experiment 2: Using tcpdump to Capture and Analyze How ICMP and ARP Work
This experiment will guide you through observing how theping command communicates with a specified target (either a machine or a network namespace) and help you understand the underlying process of how the system locates the target.
You will gain insights into the ARP-related knowledge illustrated in the diagram below.
Flush ARP Table

To understand the complete process, we can clear the ARP entries for a specific interface using the command:This flushes the ARP cache on that interface, forcing the system to perform ARP resolution again on the next communication attempt.The left image shows a comparison of the ARP table before and after clearing the entries.
Use tcpdump to record packets

Next, open two terminal windows and enter the
ns1 network namespace in both:-
In the
bottom window(as shown in the left image), run the command:This listens on theeth0interface, capturing all packets in verbose mode and writing them to the filearp_record— apcapfile you can analyze later with tools like Wireshark. -
In the
top window, use thepingcommand to send an ICMP packet fromns1tons2. Before pinging, make sure the ARP table is cleared so the ARP process will be triggered fresh.
Understand How ARP Works - 1 - ARP Request
When you ping a specific IP address (for example, 10.22.33.55 of ns2 in this experiment), but there is no corresponding MAC address entry for that IP in your own namespace (ns1) ARP table, the kernel triggers the ARP request process. Here’s a brief explanation of that process:
-
Check the ARP Table
When you issue the
pingcommand, the kernel first checks the local ARP table to see if there is already a MAC address associated with the target IP. If there is, it directly uses that MAC address to send the data packet. -
ARP Request Broadcast
If the ARP table has no entry for the target IP, the kernel sends an ARP request.
-
This is a broadcast packet sent to all devices on the same network, asking “Who has this IP address?” (
Who has <target IP>?). - The ARP request contains the sender’s IP and MAC addresses, along with the target IP address.
-
Because it is a broadcast, the destination MAC address is set to
ff:ff:ff:ff:ff:ff.
-
This is a broadcast packet sent to all devices on the same network, asking “Who has this IP address?” (
- ARP Reply The device that owns the target IP responds with an ARP reply, providing its MAC address to the requester. This reply is unicast directly back to the sender.
- Update the ARP Table Upon receiving the ARP reply, the kernel updates the local ARP table by adding the target IP and its corresponding MAC address. This entry is then used for subsequent data transmissions (such as sending the ICMP echo request to complete the ping).
Understand How ARP Works - 2 - ARP Reply
Upon receiving the ARP broadcast, ns2—which owns the IP address 10.22.33.55—will reply with an ARP reply, providing its MAC address to the sender. This reply is a unicast packet, sent directly back to the requester.
ICMP Packet
Through the ARP mechanism described earlier, the target’s MAC address is resolved and completed, allowing the formation of a complete ICMP packet that can be transmitted successfully.
ICMP Sender

ICMP Replier