ARP and switching
Every interface has two addresses. The MAC address identifies the adapter on its local link. The IP address identifies the interface in the network. This page covers how one is turned into the other (ARP), and how switches use MAC addresses to forward frames. Introduction to networking describes the address format and the frame layout.
Why two addresses
Section titled “Why two addresses”| MAC address | IP address | |
|---|---|---|
| Structure | Flat: the vendor prefix says who made the card, nothing about where it is | Hierarchical: network part plus host part |
| Follows | The adapter | The place the host is attached |
| Changes when the host moves? | No | Yes, a new subnet means a new address |
| Carried by | The link layer | The network layer |
Keeping them separate lets a link carry any network protocol, not only IP, and lets a host move without changing its hardware identity. The hardware filter in the NIC also relies on it: frames for another MAC are dropped before they reach the CPU.
MAC addresses belong to interfaces, not machines. A router with four interfaces has four MACs, and a host with Wi-Fi and Ethernet has two. Virtual interfaces get their own: every container veth, VM virtual NIC, and VLAN sub-interface has a MAC.
To send an IP packet to a neighbor on the same subnet, the sender needs the neighbor’s MAC address for the frame header. The Address Resolution Protocol finds it. ARP is limited to one subnet: DNS resolves names anywhere on the internet, while ARP resolves addresses only on the local link, because its request is a broadcast and broadcasts do not cross routers.
On the same subnet
Section titled “On the same subnet”- The host checks its ARP cache for the target IP.
- On a miss, it broadcasts an ARP request in a frame addressed to
ff:ff:ff:ff:ff:ff: “who has 192.168.1.20? tell 192.168.1.10”. - Every host on the segment receives it. Only the owner of that IP answers.
- The owner replies directly (unicast) with its MAC address.
- The sender stores the pair and sends the original packet.
# Neighbor (ARP) table on Linuxip neigh show# 192.168.1.1 dev eth0 lladdr 00:11:22:aa:bb:01 REACHABLE# 192.168.1.20 dev eth0 lladdr 00:11:22:aa:bb:20 STALE
# Send an ARP probe directly. Works even when ICMP is blockedarping -I eth0 192.168.1.20Entries are not permanent. Linux tracks each neighbor through states, and an entry moves from REACHABLE to STALE after a time, and is re-verified with a probe when next used. The timing varies by operating system and device, with some network devices keeping entries for minutes. Do not rely on a fixed lifetime.
| State | Meaning |
|---|---|
REACHABLE | Recently confirmed |
STALE | Known but not confirmed recently. Used, then re-checked |
DELAY, PROBE | Being re-verified |
INCOMPLETE | Request sent, no reply yet |
FAILED | No reply. The destination is unreachable at layer 2 |
Off the subnet
Section titled “Off the subnet”The sender compares the destination against its own prefix, finds it is remote, and picks the default gateway. It then ARPs for the gateway’s MAC, not for the final destination. Take a host at 192.168.1.10 sending to 203.0.113.50 through the gateway 192.168.1.1:
| Hop | Source IP | Destination IP | Source MAC | Destination MAC |
|---|---|---|---|---|
| Host to gateway | 192.168.1.10 | 203.0.113.50 | Host | Gateway, LAN side |
| Gateway to next router | 192.168.1.10 | 203.0.113.50 | Gateway, uplink side | Next router |
(With NAT at the gateway, the source IP is rewritten on the second hop. See NAT.)
IP addresses stay the same end to end. MAC addresses are rewritten at every router. A frame’s destination MAC therefore tells you which device is the next hop, not who the final recipient is. This is how to read a capture: tcpdump -e shows the MACs, and if the destination MAC is the gateway’s, the packet is leaving the subnet.
Common ARP problems
Section titled “Common ARP problems”| Symptom | Cause |
|---|---|
ip neigh shows FAILED or INCOMPLETE for the gateway | Wrong VLAN, bad link, or the gateway is down. The problem is below IP |
| Two hosts claim the same IP | Duplicate IP. The neighbor entry flips between two MACs. arping -D checks for this |
| Intermittent loss after a failover | Peers hold the old MAC for the virtual IP. A gratuitous ARP (an unsolicited announcement) refreshes their caches, and failover tools send one |
| Traffic goes to the wrong host | ARP spoofing: an attacker answers requests with its own MAC to sit in the middle |
ARP has no authentication. Anyone on the segment can answer any request or send a gratuitous reply. Switches defend with dynamic ARP inspection, which checks replies against a trusted table (often built from DHCP snooping). More on the attack class is in Network hardening and the threat taxonomy.
Ethernet notes
Section titled “Ethernet notes”Introduction to networking shows the frame fields. A few operating details:
- Connectionless and unreliable. There is no handshake before sending and no acknowledgment. A frame that fails its CRC is dropped silently. TCP, or the application, notices the gap.
- Minimum and maximum sizes. The payload is 46 to 1,500 bytes, with padding added if needed. The 1,500-byte limit is the standard MTU. Jumbo frames of about 9,000 bytes exist, but every device on the path must agree, or large frames are dropped.
- The type field says what the payload is:
0x0800for IPv4,0x0806for ARP,0x86DDfor IPv6. It is the demultiplexing key at this layer. - Names. Standards are named by speed, signaling, and medium.
1000BASE-Tis 1 Gbit/s over twisted pair, and theSX,LX, andLRvariants are fiber. The format helps when you match an optic to a port.
Switches
Section titled “Switches”A switch forwards frames between its ports using MAC addresses. Hosts do not address a switch. They address the final destination, and the switch is invisible. Each port runs full duplex and is its own collision domain, and the switch buffers frames, so different ports can run at different speeds and over different media.
The table
Section titled “The table”A switch keeps a forwarding table (also called the MAC table, CAM table, or FDB) with three items per entry: a MAC address, the port it was seen on, and a timestamp. No one configures it. The switch learns by reading the source MAC of every frame it receives.
When a frame arrives on port x for destination MAC D:
flowchart TD
A["Frame arrives on port x<br/>for MAC D"] --> L["Learn: source MAC is on port x"]
L --> B{"D in table?"}
B -->|"No"| F["Flood to every port except x"]
B -->|"Yes, port x"| D1["Filter: drop. Already on that segment"]
B -->|"Yes, port y"| U["Forward to port y only"]
Broadcast frames (ff:ff:ff:ff:ff:ff) are always flooded. Entries that are not refreshed expire, commonly after five minutes by default, which removes hosts that were unplugged or moved.
# Linux software bridge forwarding tablebridge fdb show br br0# 00:11:22:aa:bb:20 dev eth2 master br0# 00:11:22:aa:bb:30 dev eth3 master br0
# Cisco IOS# show mac address-tableOperating consequences
Section titled “Operating consequences”- Unknown-destination flooding. A frame to an unlearned MAC goes everywhere until the reply teaches the switch. After a topology change or a table flush, traffic floods briefly. Spanning tree topology changes cause exactly that.
- MAC flooding attack. An attacker sends frames with thousands of fake source addresses until the table is full. The switch then floods everything, and the attacker sees other hosts’ traffic. Port security limits how many MACs a port may learn.
- Loops. Learning plus flooding with redundant links produces broadcast storms. STP prevents them by blocking links.
- Isolation is partial. A switch isolates unicast traffic, but broadcasts reach every port. Large flat LANs mean lots of ARP and DHCP noise. Partitioning with VLANs or routers contains it.
Switch or router
Section titled “Switch or router”| Switch (layer 2) | Router (layer 3) | |
|---|---|---|
| Forwards by | Flat MAC address | Hierarchical IP prefix |
| Setup | Plug and play, learns itself | Addresses and routes configured or learned by protocol |
| Topology | Must be loop-free (a tree) | Any mesh. TTL prevents endless loops |
| Broadcasts | Floods them | Stops them at each interface |
| Per-packet work | Less | More |
| Suits | Local networks of up to a few hundred hosts | Large networks and anything between subnets |
Real networks use both: switches build subnets, and routers join them. A layer 3 switch is a switch with routing built into the same box. Where the boundary between layer 2 and layer 3 should sit is a design decision. Moving it to the rack or the leaf (see Data center networking) is a common choice in large networks, because it removes spanning tree and shrinks broadcast domains.
For splitting one switch into several isolated networks, see VLANs and overlays.