1. Why Does LAN Communication Need MAC Addresses and ARP?
In computer networks, device communication usually involves two important types of addresses:
- IP address: Used to identify communication endpoints at the network layer, helping devices determine which network the data should reach.
- MAC address: Used to identify network interfaces at the data link layer, helping data frames find the next-hop device within a LAN.
Suppose there are two computers in a LAN:
| Device | IPv4 Address | MAC Address |
|---|---|---|
| PC-A | 192.168.1.10 | AA:AA:AA:AA:AA:AA |
| PC-B | 192.168.1.20 | BB:BB:BB:BB:BB:BB |
When PC-A wants to send data to PC-B, the application usually only knows the destination IP address.
However, Ethernet cannot directly perform frame forwarding based on the IP address alone. It needs to know the MAC address of the destination network interface in order to construct an Ethernet frame.
This raises a question:
PC-A knows PC-B's IP address but does not know PC-B's MAC address. What should it do?
In an IPv4 LAN, this problem is usually solved by the ARP protocol.
The core function of ARP is:
to resolve a known IPv4 address into the corresponding MAC address.
2. What Is a MAC Address?
2.1 Definition of a MAC Address
MAC stands for Media Access Control and is commonly referred to as a media access control address.
A MAC address operates at the data link layer and is mainly used to identify network interfaces and participate in the sending and receiving of data frames within a LAN.
In Ethernet, a MAC address is usually 48 bits, that is, 6 bytes.
Common representations:
AA:BB:CC:DD:EE:FF
It can also be written as:
AA-BB-CC-DD-EE-FF
Or:
AABB.CCDD.EEFF
These forms represent the same 48-bit address.
MAC addresses are usually expressed in hexadecimal, with every two hexadecimal characters corresponding to one byte.
For example:
AA:BB:CC:DD:EE:FF
The corresponding binary is:
10101010 10111011 11001100
11011101 11101110 11111111
The total length is:
2.2 Structure of a MAC Address
Traditionally, a MAC address consists of two parts:
| Field | Length | Meaning |
|---|---|---|
| OUI | 24 bits | Organizationally Unique Identifier, assigned by IEEE |
| NIC Specific | 24 bits | Interface identifier portion assigned or managed by the organization |
Structure diagram:
48-bit MAC Address
┌────────────────────────┬────────────────────────┐
│ OUI │ Interface Identifier │
│ 24 bit │ 24 bit │
└────────────────────────┴────────────────────────┘
For example:
00:1A:2B:3C:4D:5E
Where:
00:1A:2B: The organization identifier portion in the traditional address allocation system.3C:4D:5E: The interface identifier portion.
Note that modern networks also include locally administered addresses, randomized MAC addresses, and other cases, so a device manufacturer cannot be determined simply from the MAC address prefix.
2.3 Two Important Flag Bits in a MAC Address
The two least significant flag bits of the first byte of a MAC address have special meaning:
- I/G bit: Individual/Group, distinguishes unicast addresses from multicast addresses.
- U/L bit: Universal/Local, distinguishes universally administered addresses from locally administered addresses.
| I/G Bit | U/L Bit | Meaning |
|---|---|---|
| 0 | 0 | Universally administered unicast address |
| 0 | 1 | Locally administered unicast address |
| 1 | 0 | Universally administered multicast address |
| 1 | 1 | Locally administered multicast address |
For example:
02:00:00:00:00:01
The two least significant bits of the first byte 02 are:
00000010
^^
│└─ U/L = 1, locally administered
└── I/G = 0, unicast
Therefore, it is a locally administered unicast MAC address.
2.4 Types of MAC Addresses
MAC addresses can be divided into three main types according to their communication scope and purpose.
| Type | Characteristic | Typical Use |
|---|---|---|
| Unicast MAC | Identifies a single network interface | Communication between two devices |
| Multicast MAC | Identifies a group of network interfaces | Send data to specific group members |
| Broadcast MAC | All bits are 1 | Send to all devices in the current Layer 2 broadcast domain |
Common broadcast MAC address:
FF:FF:FF:FF:FF:FF
When a switch receives an Ethernet frame with the broadcast MAC as the destination address, it typically floods it within the same VLAN to all ports except the receiving port.
Note: Broadcasts do not naturally cross routers, and routers typically do not forward ordinary Ethernet broadcast frames.
2.5 Are MAC Addresses Permanent?
No.
Although MAC addresses are traditionally assigned by network device manufacturers, modern operating systems and network devices can modify the MAC address used by a network interface.
Common cases include:
- A virtual machine is assigned a virtual MAC when creating a virtual network interface.
- A container network configures a MAC for a virtual interface.
- An operating system uses a random MAC address to protect user privacy.
- A network administrator manually changes the interface MAC address.
- A network device configures a locally administered MAC address through software.
For example, Linux can use ip link to change the interface MAC address.
# Show network interface information
ip link show
# Disable the network interface
sudo ip link set dev eth0 down
# Change the MAC address
sudo ip link set dev eth0 address 02:11:22:33:44:55
# Enable the network interface
sudo ip link set dev eth0 up
# Check again
ip link show eth0
In actual operation, you need to replace it with the real network interface name and consider whether network management services will override the change.
Therefore, a MAC address is not a reliable identity authentication credential and cannot be used alone to prove device identity.
III. What Is the Difference Between a MAC Address and an IP Address?
MAC addresses and IP addresses solve problems at different layers.
- IP addresses primarily solve network-layer addressing problems.
- MAC addresses primarily solve link-layer frame addressing problems.
| Comparison Dimension | MAC Address | IP Address |
|---|---|---|
| Layer | Data link layer | Network layer |
| Primary Purpose | Identifies a link-layer interface | Identifies a network-layer communication endpoint |
| Address Length | Ethernet is usually 48 bits | IPv4 is 32 bits, IPv6 is 128 bits |
| Representation | Hexadecimal | IPv4 dotted decimal, IPv6 colon-separated hexadecimal |
| Scope | Current link or Layer 2 network | Can span multiple networks |
| Allocation Method | Hardware or software configuration | Static configuration, DHCP, SLAAC, etc. |
| Main Devices Used | Switches, network interface cards | Routers, hosts |
3.1 A Key Difference: MAC Addresses Do Not Handle Cross-Network Addressing
Assume:
PC-A:
IP = 192.168.1.10
MAC = AA:AA:AA:AA:AA:AA
PC-B:
IP = 192.168.2.20
MAC = BB:BB:BB:BB:BB:BB
The two computers are on different network segments and communicate through a router in between.
When PC-A sends data, it does not directly use PC-B's MAC address as the destination address of the Ethernet frame.
It needs to first send the data to the default gateway.
Assume the default gateway is:
IP = 192.168.1.1
MAC = CC:CC:CC:CC:CC:CC
The Ethernet frame constructed by PC-A:
| Field | Content |
|---|---|
| Source MAC | AA:AA:AA:AA:AA:AA |
| Destination MAC | CC:CC:CC:CC:CC:CC |
| Source IP | 192.168.1.10 |
| Destination IP | 192.168.2.20 |
There is a very important rule here:
The destination IP of an IP packet usually remains the final destination IP, while the destination MAC of an Ethernet frame points to the next-hop device on the current link.
After a router receives a data frame, it removes the original Layer 2 encapsulation, selects the next hop based on the IP routing table, and then re-encapsulates it using a new link-layer address.
Therefore, MAC addresses usually function only on the current link, while IP addresses are responsible for end-to-end network addressing throughout the process.
3.2 How MAC Addresses and IP Addresses Work Together
They can be understood as two different questions:
| Address | Problem to Solve |
|---|---|
| IP address | Which network-layer destination should the data ultimately reach? |
| MAC address | To whom should the data frame be delivered on the current link? |
This is also why network communication usually needs to use both IP and MAC addresses.
4. What Is the ARP Protocol?
4.1 Definition of ARP
ARP stands for Address Resolution Protocol, known in Chinese as 地址解析协议.
ARP is an address resolution mechanism in IPv4 networks, used to resolve an IPv4 address into the corresponding link-layer address.
In Ethernet environments, the most common use of ARP is:
IPv4 address → MAC address
For example:
Known:
192.168.1.20
Need to query:
BB:BB:BB:BB:BB:BB
The host asks devices on the local network via an ARP request:
Who owns 192.168.1.20?
Please tell 192.168.1.10 your MAC address.
After the target device receives the request, if it confirms that the IP address belongs to itself, it returns an ARP reply.
4.2 At Which Layer Does ARP Work?
ARP is responsible for resolving between IPv4 addresses and link-layer addresses.
From a protocol layering perspective, it serves the address mapping between the network layer and the data link layer, but it does not fully correspond to any single pure layer in the traditional TCP/IP layering model.
In an Ethernet IPv4 environment:
- ARP messages are encapsulated directly in Ethernet frames.
- The Ethernet type field is
0x0806. - ARP does not use TCP or UDP ports.
- ARP requests are usually sent via Ethernet broadcast.
- ARP replies are usually returned to the requester as unicast.
The ARP frame structure differs from that of IP packets; ARP cannot simply be understood as a UDP service.
4.3 Main Fields of an ARP Message
An ARP message contains the following fields:
| Field | Length | Meaning |
|---|---|---|
| Hardware Type | 16 bits | Hardware type, e.g., 1 for Ethernet |
| Protocol Type | 16 bits | Protocol type, e.g., 0x0800 for IPv4 |
| Hardware Size | 8 bits | Hardware address length; for Ethernet MAC, it is 6 |
| Protocol Size | 8 bits | Protocol address length; for IPv4, it is 4 |
| Opcode | 16 bits | Opcode; 1 for request, 2 for reply |
| Sender MAC | 48 bits | Sender MAC address |
| Sender IP | 32 bits | Sender IPv4 address |
| Target MAC | 48 bits | Target MAC address |
| Target IP | 32 bits | Target IPv4 address |
In an ARP request, the target MAC address is usually filled with all zeros because the requester does not yet know the target device's MAC address.
Main differences between ARP requests and replies:
| Field | ARP Request | ARP Reply |
|---|---|---|
| Opcode | 1 | 2 |
| Sender MAC | Requester MAC | Responder MAC |
| Sender IP | Requester IP | Responder IP |
| Target MAC | Usually all zeros | Requester MAC |
| Target IP | IP to be queried | Requester IP |
| Ethernet destination MAC | Broadcast MAC | Usually the requester MAC |
5. How Does ARP Perform Address Resolution?
Suppose there are three devices on the local network:
| Device | IP Address | MAC Address |
|---|---|---|
| PC-A | 192.168.1.10 | AA:AA:AA:AA:AA:AA |
| PC-B | 192.168.1.20 | BB:BB:BB:BB:BB:BB |
| PC-C | 192.168.1.30 | CC:CC:CC:CC:CC:CC |
PC-A needs to send data to PC-B but does not yet have PC-B's MAC address in its cache.
5.1 Step 1: Check the ARP Cache
Before sending data, PC-A first checks its local ARP cache.
If the cache already contains:
192.168.1.20 → BB:BB:BB:BB:BB:BB
It can directly use this MAC address to construct the Ethernet frame without broadcasting another ARP request.
If no matching entry is found, it needs to perform address resolution.
5.2 Step 2: Send ARP Request
PC-A constructs an ARP request:
Sender IP: 192.168.1.10
Sender MAC: AA:AA:AA:AA:AA:AA
Target IP: 192.168.1.20
Target MAC: 00:00:00:00:00:00
The destination MAC address of the Ethernet frame is:
FF:FF:FF:FF:FF:FF
This means the frame will be sent to all devices in the current Layer 2 broadcast domain.
5.3 Step 3: Switch Floods the Broadcast Frame
After the switch receives the broadcast frame sent by PC-A, it performs MAC address learning and floods the frame to other ports in the same VLAN.
Both PC-B and PC-C receive this ARP request.
However, only PC-B, whose IP address is 192.168.1.20, confirms that the target IP matches its own address.
PC-C finds that the target IP is not its own, so it does not respond as the target device.
5.4 Step 4: PC-B Returns an ARP Reply
PC-B returns an ARP reply:
Sender IP: 192.168.1.20
Sender MAC: BB:BB:BB:BB:BB:BB
Target IP: 192.168.1.10
Target MAC: AA:AA:AA:AA:AA:AA
PC-B typically sends the ARP reply to PC-A as a unicast.
5.5 Step 5: Update the ARP Cache
After PC-A receives the reply, it records the address mapping:
192.168.1.20 → BB:BB:BB:BB:BB:BB
After that, it can use this mapping to construct Ethernet frames.
5.6 Complete ARP Resolution Process
flowchart TD
A["PC-A needs to send data to PC-B"] --> B["Check the local ARP cache"]
B --> C{"Does a mapping for the target IP exist?"}
C -->|Yes| D["Read the target MAC address"]
C -->|No| E["Build an ARP Request"]
E --> F["Send an Ethernet broadcast frame"]
F --> G["Switch floods within the VLAN"]
G --> H["LAN devices receive the request"]
H --> I{"Does the target IP belong to this host?"}
I -->|No| J["Ignore the request"]
I -->|Yes| K["Build an ARP Reply"]
K --> L["Unicast back to the requester"]
L --> M["Requester updates its ARP cache"]
M --> D
D --> N["Build the Ethernet data frame"]
N --> O["Send the IP packet"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style C fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style D fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style E fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style F fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style G fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style H fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style I fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style J fill:#F0F1F3,stroke:#C8CDD3,color:#64748B
style K fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style L fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style M fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style N fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style O fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
This diagram shows the core process of ARP address resolution.
Note that an ARP request is not performed once for every IP packet sent. As long as the mapping in the cache remains valid, the host can reuse the cached entry.
6. How Does a Switch Cooperate with ARP to Complete Communication?
ARP handles address resolution, and the switch forwards Ethernet frames based on MAC addresses.
The two take on different responsibilities.
6.1 The Switch's MAC Address Table
An Ethernet switch typically maintains a MAC address forwarding table, also called a CAM table or MAC address table.
Table entries typically include:
| Field | Meaning |
|---|---|
| MAC Address | Source MAC address that has been learned |
| VLAN | VLAN it belongs to |
| Port | Corresponding switch port |
| Type | Dynamically learned or statically configured |
| Aging Time | Aging time of the entry |
For example:
| MAC Address | VLAN | Switch Port |
|---|---|---|
| AA:AA:AA:AA:AA:AA | 10 | Gi0/1 |
| BB:BB:BB:BB:BB:BB | 10 | Gi0/2 |
| CC:CC:CC:CC:CC:CC | 10 | Gi0/3 |
6.2 How Does a Switch Learn MAC Addresses?
A switch typically learns device locations from the source MAC address of the Ethernet frames it receives.
Suppose PC-A sends a data frame through port Gi0/1:
Source MAC: AA:AA:AA:AA:AA:AA
Destination MAC: FF:FF:FF:FF:FF:FF
After the switch receives the frame:
- It reads the source MAC address.
- It associates the source MAC address with the receiving port and VLAN.
- It updates the MAC address table.
- It checks the destination MAC address.
- If the destination address is the broadcast address, it floods the frame within the corresponding VLAN.
6.3 How Does a Switch Forward Unicast Frames?
When PC-A has already obtained PC-B's MAC address and sends a data frame:
Source MAC: AA:AA:AA:AA:AA:AA
Destination MAC: BB:BB:BB:BB:BB:BB
The switch queries the MAC address table.
If it already knows that PC-B is on Gi0/2, it forwards the data frame only to Gi0/2.
If the destination MAC address is not found, unknown unicast flooding is usually performed within the current VLAN.
6.4 Switch Forwarding Process
flowchart TD
A["Switch receives Ethernet frame"] --> B["Read source MAC and VLAN"]
B --> C["Learn or update MAC address table"]
C --> D["Read destination MAC"]
D --> E{"Destination MAC type?"}
E -->|Broadcast or multicast| F["Process according to corresponding forwarding rules"]
E -->|Unicast| G["Query MAC address table"]
G --> H{"Does a valid entry exist?"}
H -->|Yes| I["Check target port and VLAN"]
H -->|No| J["Perform unknown unicast flooding"]
I --> K{"Is the target port the ingress port?"}
K -->|Yes| L["Filter this frame"]
K -->|No| M["Forward to target port"]
F --> N["Complete forwarding processing"]
J --> N
L --> N
M --> N
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style C fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style D fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style E fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style F fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style G fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style H fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style I fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style J fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style K fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style L fill:#F0F1F3,stroke:#C8CDD3,color:#64748B
style M fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style N fill:#F6FAF7,stroke:#DCE9E0,color:#334155
Note:
- Broadcast frames are usually flooded within the VLAN.
- Unknown unicast frames are usually flooded within the VLAN.
- Known unicast frames are usually forwarded to the specific destination port.
- A switch does not automatically learn the mapping between the target IP and MAC address just because it receives an ARP request.
An ordinary Layer 2 switch mainly learns MAC addresses and is not responsible for building a complete IPv4-to-MAC mapping.
7. Who Does ARP Query During Cross-Subnet Communication?
This is the most error-prone part of understanding ARP.
Many people think:
When a host sends data to a remote server, it needs to use ARP to query the remote server's MAC address.
In fact, this is usually not the case.
When the destination IP is not on the local subnet, the host needs to resolve the MAC address of the next-hop default gateway, not the MAC address of the remote server.
7.1 Same-Subnet Communication
Assume:
PC-A:
IP: 192.168.1.10
Mask: 255.255.255.0
PC-B:
IP: 192.168.1.20
Mask: 255.255.255.0
Both devices are on the same IPv4 subnet.
PC-A determines that the destination IP is on the same subnet as itself, so it can directly query PC-B's MAC address via ARP.
Ethernet frame:
| Field | Content |
|---|---|
| Source MAC | PC-A's MAC |
| Destination MAC | PC-B's MAC |
| Source IP | 192.168.1.10 |
| Destination IP | 192.168.1.20 |
7.2 Cross-Subnet Communication
Assume:
PC-A:
IP: 192.168.1.10
Gateway: 192.168.1.1
Router:
LAN IP: 192.168.1.1
LAN MAC: CC:CC:CC:CC:CC:CC
Remote server:
IP: 192.168.2.20
PC-A determines that the destination IP does not belong to the local subnet.
Therefore, PC-A sends the data to the default gateway.
First, it needs to resolve:
192.168.1.1 → CC:CC:CC:CC:CC:CC
Then it constructs the Ethernet frame:
| Field | Content |
|---|---|
| Source MAC | PC-A's MAC |
| Destination MAC | Router LAN interface MAC |
| Source IP | 192.168.1.10 |
| Destination IP | 192.168.2.20 |
After receiving the data, the router determines the next hop according to the routing table and re-encapsulates the data frame on the next link.
If the next hop is on an Ethernet link, the router may need to query the next hop's MAC address via ARP.
7.3 Same-Subnet vs. Cross-Subnet ARP Comparison
| Comparison Item | Same-Subnet Communication | Cross-Subnet Communication |
|---|---|---|
| Destination IP | Within the local subnet | Remote subnet |
| ARP Query Target | Destination host | Default gateway or the next hop selected by routing |
| Ethernet Destination MAC | Destination host MAC | Next-hop MAC |
| IP Destination Address | Destination host IP | Final destination IP |
| Passes Through a Router | Usually not required | Required |
7.4 Complete Cross-Subnet Communication Process
flowchart TD
A["PC-A generates a packet destined for the target IP"] --> B["Determines the destination subnet based on the subnet mask"]
B --> C{"Does the destination belong to the local subnet?"}
C -->|Yes| D["Uses the destination host as the next hop"]
C -->|No| E["Queries the routing table and default gateway"]
D --> F["Checks the destination MAC cache"]
E --> G["Determines the next-hop gateway"]
G --> H["Checks the gateway MAC cache"]
F --> I{"Is a MAC mapping already available?"}
H --> I
I -->|No| J["Sends an ARP request"]
J --> K["Receives an ARP reply"]
K --> L["Updates the neighbor cache"]
I -->|Yes| M["Reads the next-hop MAC"]
L --> M
M --> N["Encapsulates the Ethernet frame"]
N --> O["Sends to the next hop"]
O --> P["Router queries the routing table"]
P --> Q["Determines the egress interface and next hop"]
Q --> R["Obtains the next-hop link address"]
R --> S["Re-encapsulates the data frame"]
S --> T["Continues forwarding to the destination network"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style C fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style D fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style E fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style F fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style G fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style H fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style I fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style J fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style K fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style L fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style M fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style N fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style O fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style P fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style Q fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style R fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style S fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style T fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
In this process, each time the router traverses a new Ethernet link, it may need to re-resolve the MAC address of the next hop.
Therefore, as the same IP packet passes through multiple routers, the Layer 2 source MAC and destination MAC usually keep changing, while the IP source and destination addresses usually remain unchanged.
In special cases, mechanisms such as NAT, tunnels, and proxies may modify or encapsulate IP-layer information.
VIII. ARP Cache: Why Don't We Need to Broadcast Every Time?
If ARP broadcasting were performed every time data is sent, it would cause a large amount of unnecessary network overhead.
Therefore, operating systems typically maintain an ARP cache.
8.1 What Is the ARP Cache?
The ARP cache stores the mapping between IPv4 addresses and MAC addresses.
For example:
| IPv4 Address | MAC Address | State |
|---|---|---|
| 192.168.1.1 | CC:CC:CC:CC:CC:CC | REACHABLE |
| 192.168.1.20 | BB:BB:BB:BB:BB:BB | STALE |
| 192.168.1.30 | DD:DD:DD:DD:DD:DD | DELAY |
When a host needs to send data to an IP address, it can first look up the cache.
If the mapping is valid, it is used directly.
If no mapping exists, address resolution is triggered.
8.2 ARP Cache States
In systems such as Linux, the neighbor table may contain the following states:
| State | Meaning |
|---|---|
| INCOMPLETE | Resolving the neighbor address |
| REACHABLE | The neighbor was recently confirmed reachable |
| STALE | A neighbor entry exists but needs to be reconfirmed |
| DELAY | Waiting for an upper layer to trigger further confirmation |
| PROBE | Actively probing the neighbor |
| FAILED | Address resolution or reachability confirmation failed |
| PERMANENT | Permanent static neighbor entry |
These states are part of the neighbor reachability management mechanism; they do not mean that every system presents or handles the cache in exactly the same way.
8.3 How Is the ARP Cache Updated?
Common update scenarios include:
- Learning address mappings through ARP requests and replies.
- Updating states through neighbor reachability detection during network communication.
- Dynamic entries aging out after a period of time.
- Administrators manually deleting or adding static entries.
- Network interface or network configuration changes invalidating the relevant entries.
8.4 Why Can the ARP Cache Become Stale?
Devices may undergo the following changes:
- The network adapter is replaced.
- The IP address is reassigned.
- The network interface is switched.
- A virtual machine is migrated.
- The device's MAC address is changed.
- The network topology changes.
If the cache still points to the old MAC address, communication problems may occur.
Operating systems need to update mappings through mechanisms such as cache aging and re-probing.
9. Several Special ARP Mechanisms
ARP is not just ordinary address lookup; it also has some special uses.
9.1 Gratuitous ARP: Free ARP
Gratuitous ARP is usually translated as "free ARP" or "unsolicited ARP."
It is an ARP packet actively sent by a device, usually to announce the mapping between its own IPv4 address and MAC address, or to detect IP address conflicts.
Typical uses:
- Detecting IP address conflicts.
- Notifying LAN devices to update their ARP caches.
- Updating the address mappings of neighbor devices during high-availability cluster failover.
- Notification after a network interface address changes.
For example, a server takes over a virtual IP:
Virtual IP: 192.168.1.100
New MAC: DD:DD:DD:DD:DD:DD
The server can send a Gratuitous ARP so that LAN devices promptly update the MAC address corresponding to that IP.
9.2 ARP Probe: ARP Probing
ARP Probe is often used for IPv4 address conflict detection.
When a device is about to use an IPv4 address, it can first send a probe request to confirm whether another device on the LAN is already using that address.
Typical scenario:
The device is about to use:
192.168.1.100
but has not yet formally configured that address.
It can send an ARP Probe to ask whether any device is currently using this IP.
If it receives a response from another device, it must consider an IP address conflict and cannot use that address directly.
9.3 Proxy ARP
Proxy ARP is a mechanism in which a router or another network device responds to ARP requests on behalf of the target host.
Suppose:
- PC-A is on one subnet.
- The target host is on another subnet.
- The router in between has Proxy ARP enabled.
When PC-A sends an ARP request for the target IP, the router may return its own MAC address on behalf of the target host.
PC-A then sends the data frame to the router, which continues forwarding it.
Proxy ARP was once used in some special network designs, but modern networks generally prefer explicit subnet and default gateway configuration.
It can also increase the complexity of Layer 2 broadcast and address resolution behavior, so it should be used with caution.
9.4 Anomalies in ARP Requests and Responses
ARP resolution is not guaranteed to succeed.
Common causes:
- The target device is powered off.
- The target IP is misconfigured.
- The switch VLAN configuration is incorrect.
- The network link is down.
- ARP requests are filtered by security policies.
- The target device does not respond to ARP.
- Incorrect or conflicting address mappings exist in the network.
When ARP cannot resolve successfully, the host cannot obtain the next-hop MAC address, and the relevant IPv4 packets usually cannot be sent over that link.
9.5 ARP Exception Handling Process
flowchart TD
A["The host needs to resolve the target IPv4 address"] --> B["Check the ARP neighbor cache"]
B --> C{"Is a usable mapping present?"}
C -->|Yes| D["Use the MAC address from the cache"]
C -->|No| E["Send an ARP Request"]
E --> F["Wait for ARP Reply"]
F --> G{"Was a valid response received?"}
G -->|Yes| H["Validate the response and update the cache"]
G -->|No| I["Wait or perform further probing"]
I --> J{"Has the retry limit been exceeded?"}
J -->|No| E
J -->|Yes| K["Mark resolution as failed"]
H --> D
D --> L["Continue sending data"]
K --> M["Report neighbor unreachable or communication failure"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style C fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style D fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style E fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style F fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style G fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style H fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style I fill:#F6FAF7,stroke:#DCE9E0,color:#334155
style J fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style K fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style L fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style M fill:#F4E4E4,stroke:#D9A6A6,color:#854545
10. ARP Security Issues: ARP Spoofing and Man-in-the-Middle Attacks
ARP was designed on the assumption that devices within a local network trust one another.
Traditional ARP lacks an identity authentication mechanism, so it is usually difficult for a device to confirm from an ARP message alone whether the sender actually owns the IP address it claims.
This creates security risks.
10.1 What Is ARP Spoofing?
ARP spoofing is when an attacker forges ARP messages so that other devices incorrectly establish a mapping between an IP address and a MAC address.
For example, in a normal network:
Gateway IP:
192.168.1.1
Gateway MAC:
CC:CC:CC:CC:CC:CC
The attacker tries to make PC-A mistakenly believe that:
192.168.1.1 → DD:DD:DD:DD:DD:DD
As a result, PC-A may hand frames that should have gone to the gateway over to a device controlled by the attacker.
10.2 The Basic Principle of ARP Spoofing
Under normal circumstances, PC-A's ARP cache contains the correct gateway mapping.
After the attacker forges an ARP reply, PC-A may incorrectly update its cache.
PC-A then sends its traffic to the attacker.
If the attacker further forwards this traffic, a man-in-the-middle attack can take shape.
10.3 The Basic Flow of ARP Spoofing
flowchart TD
A["Normal network communication"] --> B["PC-A caches the correct gateway MAC"]
B --> C["Attacker forges an ARP reply"]
C --> D["PC-A receives an incorrect address mapping"]
D --> E["ARP cache is incorrectly updated"]
E --> F["PC-A sends traffic to the attacker"]
F --> G{"Does the attacker continue forwarding traffic?"}
G -->|Yes| H["A man-in-the-middle communication may form"]
G -->|No| I["Communication may be interrupted"]
H --> J["Traffic is at risk of being intercepted or tampered with"]
I --> K["Network communication is abnormal"]
style A fill:#E0F0FE,stroke:#93BCE8,color:#1E4976
style B fill:#DCEFE5,stroke:#A3CDB5,color:#24563F
style C fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style D fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style E fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style F fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style G fill:#FFF4D6,stroke:#E8C979,color:#6B5421
style H fill:#E9E3FA,stroke:#B7A9DF,color:#51417A
style I fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style J fill:#F4E4E4,stroke:#D9A6A6,color:#854545
style K fill:#F0F1F3,stroke:#C8CDD3,color:#64748B
Note:
ARP spoofing does not mean the attacker can necessarily read encrypted HTTPS content, but it may cause traffic hijacking, denial of service, connection interference, and other issues.
10.4 How to defend against ARP spoofing?
Common defense measures:
| Defense measure | Principle | Applicable scenario |
|---|---|---|
| Dynamic ARP Inspection | Check whether ARP packets are legitimate | Enterprise switched network |
| DHCP Snooping | Establish trusted DHCP address binding information | Enterprise access network |
| Static ARP | Manually fix IP-to-MAC mappings | A small number of critical devices |
| Network segmentation | Reduce the Layer 2 broadcast domain | Large LANs |
| Port security | Limit the MAC addresses allowed on switch ports | Access-layer switches |
| Endpoint detection | Detect abnormal ARP mapping changes | Host security management |
| HTTPS and TLS | Protect application-layer communication content | Internet services |
Among them, Dynamic ARP Inspection usually checks ARP packets against the binding information maintained by DHCP Snooping.
If the IP-to-MAC relationship in an ARP packet does not match the trusted binding information, the switch can discard it.
Static ARP is suitable for a small number of special devices, but maintenance costs are high for large-scale deployment, and it cannot solve all link-layer security issues.
11. Why Does IPv6 Not Use ARP?
ARP primarily serves IPv4 networks.
IPv6 does not use ARP; instead, it uses the Neighbor Discovery Protocol (NDP) in ICMPv6.
NDP provides more functions than traditional ARP.
In addition to address resolution, it also supports:
- Neighbor reachability detection.
- Router discovery.
- Prefix discovery.
- Functions related to address autoconfiguration.
- Redirects.
- Duplicate address detection.