Skip to content
Documentation Background

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.


MAC addressIP address
StructureFlat: the vendor prefix says who made the card, nothing about where it isHierarchical: network part plus host part
FollowsThe adapterThe place the host is attached
Changes when the host moves?NoYes, a new subnet means a new address
Carried byThe link layerThe 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.

  1. The host checks its ARP cache for the target IP.
  2. 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”.
  3. Every host on the segment receives it. Only the owner of that IP answers.
  4. The owner replies directly (unicast) with its MAC address.
  5. The sender stores the pair and sends the original packet.
Terminal window
# Neighbor (ARP) table on Linux
ip 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 blocked
arping -I eth0 192.168.1.20

Entries 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.

StateMeaning
REACHABLERecently confirmed
STALEKnown but not confirmed recently. Used, then re-checked
DELAY, PROBEBeing re-verified
INCOMPLETERequest sent, no reply yet
FAILEDNo reply. The destination is unreachable at layer 2

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:

HopSource IPDestination IPSource MACDestination MAC
Host to gateway192.168.1.10203.0.113.50HostGateway, LAN side
Gateway to next router192.168.1.10203.0.113.50Gateway, uplink sideNext 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.

SymptomCause
ip neigh shows FAILED or INCOMPLETE for the gatewayWrong VLAN, bad link, or the gateway is down. The problem is below IP
Two hosts claim the same IPDuplicate IP. The neighbor entry flips between two MACs. arping -D checks for this
Intermittent loss after a failoverPeers 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 hostARP 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.


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: 0x0800 for IPv4, 0x0806 for ARP, 0x86DD for IPv6. It is the demultiplexing key at this layer.
  • Names. Standards are named by speed, signaling, and medium. 1000BASE-T is 1 Gbit/s over twisted pair, and the SX, LX, and LR variants are fiber. The format helps when you match an optic to a port.

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.

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.

Terminal window
# Linux software bridge forwarding table
bridge 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-table
  • 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 (layer 2)Router (layer 3)
Forwards byFlat MAC addressHierarchical IP prefix
SetupPlug and play, learns itselfAddresses and routes configured or learned by protocol
TopologyMust be loop-free (a tree)Any mesh. TTL prevents endless loops
BroadcastsFloods themStops them at each interface
Per-packet workLessMore
SuitsLocal networks of up to a few hundred hostsLarge 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.