L2 · switching · reviewed
Ethernet
Ethernet framing, MAC learning and forwarding
Delivers a frame to a MAC address on a segment, and learns where every address lives by watching what arrives.
Presenter modeEmbed this figure
Why it exists
Every device on a shared medium hears everything. Addressing exists so a receiver can tell which frames are for it, and switching exists so that a frame does not have to reach every receiver in order to reach one. IEEE 802.3-2022 §3.1
A switch has no directory and nothing registers with it. It builds its forwarding table by reading the source address of every frame that arrives and remembering which port it came from — which means a host that never transmits cannot be found. IEEE 802.1D-2004 §7.8
Everything else at layer 2 is built on this. VLANs scope the learning, spanning tree stops the flooding looping, and both assume the switch is learning from traffic rather than being told.
A switch learns by listening, not by asking
Nothing tells a switch where a host is. It reads the source address of every frame that arrives and remembers the port it came in on.
The switch has just booted. Its filtering database is empty — it knows nothing about any of the three hosts, and nothing will tell it. A · aa:aa. Switch: Known addresses 0. B · bb:bb. C · cc:cc.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| A · aa:aa | host | — |
| Switch | switch | Known addresses: 0 |
| B · bb:bb | host | — |
| C · cc:cc | host | — |
| A · aa:aa — Switch | link | up · Gi1 |
| Switch — B · bb:bb | link | up · Gi2 |
| Switch — C · cc:cc | link | up · Gi3 |
The switch has just booted. Its filtering database is empty — it knows nothing about any of the three hosts, and nothing will tell it.
What changed
- Switch: Known addresses → 0
- Emphasis on Switch
Filtering database
show mac address-table| Address | Port | Age |
|---|
How it works
A frame carries a destination and a source address. The switch looks the destination up in its filtering database to decide where to send it, and writes the source into that database against the port it arrived on. IEEE 802.1D-2004 §7.9
An unknown destination is flooded out every port in the VLAN except the one it arrived on. This is correct rather than a fallback: dropping it would make a silent host permanently unreachable. IEEE 802.1D-2004 §7.7
Entries age out after five minutes by default, refreshed by frames received *from* the address rather than sent to it. Silence and absence are indistinguishable to a switch, which is the root of unicast flooding. IEEE 802.1D-2004 §7.9.2
The same address arriving on a different port moves the entry immediately, with no verification. That is what makes migration and failover work, and what makes a loop present as an address flapping between two ports.
On the wire
Constructed examples, encoded from the field table below them — not captured traffic.
- Physical
- A preamble and start-of-frame delimiter precede this, and the hardware removes them before any capture sees the frame. IEEE 802.3-2022
- MAC header
- Destination address, source address, and the EtherType naming the payload. IEEE 802.3-2022
- Payload and FCS
- Between 46 and 1500 octets, padded to the minimum, followed by a four-octet frame check sequence. IEEE 802.3-2022
Configure it
mac address-table aging-time 14400Raises the ageing time to match the router’s four-hour ARP timeout, so the two expire together and the window where the router sends to an address the switch has forgotten disappears.
Common mistake: Changing one side only. Aligning them is the point — a shorter ARP timeout achieves the same thing and is often the better half to change.
IEEE 802.1D-2004 §7.9.2
mac address-table static 0011.2233.4455 vlan 10 interface GigabitEthernet1/0/5Pins an address that would otherwise age out. Appropriate for an appliance that only ever answers and never initiates.
interface GigabitEthernet1/0/5 switchport port-security switchport port-security maximum 3 switchport port-security violation restrictCaps how many addresses one port may contribute. This bounds a table-exhaustion attack to a single port rather than the whole switch.
Common mistake: Using the default `shutdown` violation mode on a port with a phone and a PC behind it. Three is a realistic maximum there; one is not.
interface GigabitEthernet1/0/5 storm-control broadcast level pps 1k storm-control unicast level pps 10k storm-control action trapRate-limits flooded traffic per port. It caps the damage from a flooding event without addressing the cause, which is why the trap matters more than the limit.
Verify
show mac address-table count- Entries used against the platform limit.
show mac address-table aging-time- The configured ageing time, per VLAN if set that way.
show interfaces counters- Per-port traffic, which is where flooding shows up.
Caveats
- Ageing time can be set globally and per VLAN; the per-VLAN value wins and is easy to forget.
- Port security counts addresses, and a hypervisor uplink legitimately presents many.
When it breaks
Symptom first, because that is what you have when it happens.
Ports that should be idle show steady inbound traffic, and a wireless network becomes slow while the wired one seems fine.
Narrow it down
- Capture on an uninvolved port and check whether the traffic is addressed to somebody else.
- Compare the switch ageing time against the router ARP timeout.
- Look for an asymmetric conversation — one side sending constantly, the other rarely.
Cause
The quiet side aged out of the filtering database while the conversation was still running, so every packet toward it is an unknown unicast and is flooded.
Fix
Align the ageing time with the ARP timeout so the two expire together. Reducing VLAN size limits the damage but does not remove the cause.
IEEE 802.1D-2004 §7.9.2Log messages report a MAC address moving repeatedly between two ports, and connectivity in that VLAN is intermittent.
Narrow it down
- Read the two ports named in the message — they bound the loop.
- Check whether spanning tree is running on both and whether either is an edge port.
- Look for a device bridging the two, often an unmanaged switch or a hypervisor.
Cause
A loop is delivering copies of the same host’s frames to two ports. The switch believes the most recent frame, so the entry oscillates.
Fix
Break the loop. Then find why spanning tree did not — a disabled instance, a BPDU filter, or a device that does not forward BPDUs.
A switch starts flooding all traffic, and its table is at capacity with addresses nobody recognises.
Narrow it down
- Count the entries against the platform limit.
- Look at whether the addresses are plausible or random.
- Check which port they are being learned on.
Cause
The filtering database is full, so nothing new can be learned and everything unknown is flooded. Either the VLAN is genuinely too large, or a host is forging source addresses to force exactly this.
Fix
Port security limits how many addresses a port may learn, which caps the attack at one port. A large flat VLAN needs splitting rather than limiting.
A device is reachable only after something is sent from it, and unreachable again later.
Narrow it down
- Check whether its address is in the table at all.
- Ping from the device and see whether it becomes reachable.
- Look at how often it transmits unprompted.
Cause
A switch learns only from transmitted frames. A device that listens and rarely sends is invisible until it does, and is forgotten again after the ageing time.
Fix
A static entry pins it. In practice most such devices are appliances that can be configured to send something periodically, which is the more maintainable answer.
A link is up and passes small traffic, and throughput collapses under load. One end reports collisions and the other reports errors.
Narrow it down
- Compare the duplex setting reported at each end — they will differ.
- Look for late collisions on the half-duplex end, which is the specific signature.
- Check whether one end has speed and duplex forced and the other is auto-negotiating.
Cause
One end is half duplex and the other full. The half-duplex end defers and detects collisions; the full-duplex end transmits whenever it likes. Every simultaneous transmission is a collision one end sees and the other does not.
Fix
Auto-negotiate at both ends, or force both. Forcing one end is what causes this — a forced end sends no negotiation, so the auto end falls back to half duplex and the two disagree.
Design notes
Align the switch ageing time with the router ARP timeout. The default pairing — five minutes against four hours — guarantees a window where the router keeps sending to an address the switch has forgotten, and every packet in it is flooded.
A MAC flap message is a loop report. It names both ports involved, needs no spanning tree, and frequently arrives before anything else does. Treat it as the first thing to read when a VLAN misbehaves.
Table capacity is finite and much smaller than people expect on access switches. Filling it — by accident on a large flat VLAN, or deliberately with forged source addresses — makes the switch flood everything, which is the point of the attack.
Misconceptions
- “A switch learns from the destination address.”
- It learns from the source. The destination is looked up to decide where to forward; the source is what gets written to the table — which is why a switch learns about a host from a frame that was addressed to somebody else. IEEE 802.1D-2004 §7.8
- “Flooding an unknown unicast is a failure.”
- It is the correct behaviour and the only safe one. Dropping the frame would make any host unreachable until it happened to transmit. Flooding is a problem when it is continuous, not when it happens. IEEE 802.1D-2004 §7.7
- “A switch is a fast hub.”
- A hub repeats every frame to every port and shares one collision domain. A switch forwards to one port and gives each port its own, which is why full duplex became possible and why collisions effectively disappeared.
- “A MAC address is burned in and cannot change.”
- It is assigned in manufacturing and freely overridable in software. Virtual machines, bonded interfaces and privacy features all set their own, and the switch has no way to know or care.
More walkthroughs
Unicast flooding that nobody noticesfailure
A one-way conversation ages out of the table while it is still going. Every packet in the other direction is then flooded to the whole VLAN.
A backup runs from the server to the client. The server transmits continuously; the client acknowledges rarely and sends almost nothing else. Backup server: Sending continuously. Switch. Client · quiet: Sending rarely. Everything else.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| Backup server | host | Sending: continuously |
| Switch | switch | — |
| Client · quiet | host | Sending: rarely |
| Everything else | host | — |
| Backup server — Switch | link | up |
| Switch — Client · quiet | link | up |
| Switch — Everything else | link | up |
A backup runs from the server to the client. The server transmits continuously; the client acknowledges rarely and sends almost nothing else.
What changed
- Backup server: Sending → continuously
- Client · quiet: Sending → rarely
- Emphasis on Backup server ↔ Switch
An address that moves, and one that appears todesign-choice
A switch believes the most recent frame. That is what makes failover work and what makes a loop look like a flapping host.
A virtual machine with address vv:vv is learned on Gi1. Traffic for it goes there and nowhere else. Switch: vv:vv Gi1. Gi1. Gi2.
- Link
- Blocking
- Packet in flight
- Discarded
- Emphasis
Text equivalent of this diagram
| Element | Kind | State |
|---|---|---|
| Switch | switch | vv:vv: Gi1 |
| Gi1 | host | — |
| Gi2 | host | — |
| Switch — Gi1 | link | up |
| Switch — Gi2 | link | up |
A virtual machine with address vv:vv is learned on Gi1. Traffic for it goes there and nowhere else.
What changed
- Switch: vv:vv → Gi1
- Emphasis on Switch ↔ Gi1
Terms
- Filtering database
- A switch’s table of MAC addresses and the ports they were last seen on. Built entirely by reading the source address of arriving frames; nothing registers with it.
- Flooding
- Sending a frame out every port in the VLAN except the one it arrived on. The correct response to a destination the switch has not learned.
- Unknown unicast flooding
- Flooding traffic addressed to a specific host because its entry has aged out. Harmless once; a continuous stream when one side of a conversation talks and the other rarely answers.