Sub topic 10
When a Host Moves: Updates and MAC Flapping
This chapter assumes you know how a switch learns source addresses, looks up destinations, and ages entries. It covers what happens when the table says a MAC address is behind one port and a frame from that address then arrives on another port. The cause may be a real move or a network fault, and the two look the same to the switch at first.
The learning rule that handles moves
The learning step has no special case for moves. On every frame, the switch writes the source MAC address and the ingress port into the table, and it resets the entry's timer. If an entry for that address already exists on a different port, the write overwrites it. The old port is forgotten immediately.
In the switch code from earlier in the tutorial, this is the line self.table[src] = (in_port, now). A dictionary assignment replaces any previous value, so a move is handled without extra logic.
The consequence is that the switch trusts the most recent frame. It cannot tell whether a frame came from the real owner of an address or from something else using that address. The table always reflects the last place the address was seen.
A legitimate move
Suppose laptop A moves from a desk port to a meeting-room port on the same switch. The sequence is:
- A is learned on port 1. The table holds
A -> port 1. - The user unplugs the cable. Most switches remove dynamic entries for a port when its link goes down, but not all do. If the entry stays, it remains until it ages out.
- The laptop connects to port 3 and sends any frame, such as a DHCP request or an ARP message.
- The switch learns A on port 3 and overwrites the entry.
Between steps 2 and 4, frames sent to A may go to the old port, where nothing receives them. Once A transmits from the new port, the table is correct again. Traffic toward A recovers as soon as A sends something, not when the old entry ages out. This is why a moved host usually works within a second or two, even with a 300-second aging time.
The code below shows the overwrite using the LearningSwitch class from earlier in this tutorial.
sw = LearningSwitch(ports=[1, 2, 3])
A = '00:00:00:00:00:0a'
B = '00:00:00:00:00:0b'
sw.handle(1, A, B, now=0) # A learned on port 1
print(sw.table[A]) # (1, 0)
sw.handle(3, A, B, now=10) # A now sends from port 3
print(sw.table[A]) # (3, 10)
print(sw.handle(2, B, A, now=11)) # frame to A goes to port 3: [3]Moves that look like moves but are not
A host can legitimately appear on a different port without anyone unplugging a cable. Common cases:
- Virtual machine migration. A VM moves between hypervisors attached to different switch ports. The hypervisor usually sends a gratuitous or reverse ARP frame with the VM's MAC address as the source so that switches update quickly.
- Failover pairs. Two firewalls or servers share a virtual MAC address (for example with VRRP). When the standby takes over, the shared MAC appears on a different port.
- NIC teaming. A server with two NICs in an active/standby team may send from the same MAC on either NIC, so the address moves between two switch ports at failover.
- Wireless roaming. A client moves between access points, which connect to different switch ports.
In all of these, the move is real and happens once or occasionally. The table updates and traffic continues.
MAC flapping
MAC flapping is a condition where the same MAC address keeps alternating between two or more ports in the table. Instead of one overwrite, the switch overwrites the entry repeatedly, sometimes many times per second.
A flapping entry cannot be correct, because the address is not physically in two places at once. Flapping always means that frames with the same source MAC address are reaching the switch through more than one path. The switch sees A on port 1, then A on port 2, then port 1 again, and updates each time.
Common causes
| Cause | What happens |
|---|---|
| Layer 2 loop | A broadcast or flooded frame circulates through redundant links. The switch receives copies of the same frame, with the same source MAC, on different ports. |
| Duplicate MAC address | Two devices are configured with the same MAC, through cloned VMs, a misconfigured virtual MAC, or deliberate spoofing. Each sends frames from its own port. |
| Misconfigured NIC teaming or bonding | A team in a mode that sends from one MAC on several links, connected to switches that do not expect it (for example, no link aggregation configured on the switch side). |
| Spanning tree failure | Redundant links are all forwarding because STP is disabled, blocked by a filter, or not receiving BPDUs. |
The loop case is the most serious. A flood in a looped topology does not stop, so the same source address keeps arriving on different ports, and the flapping is a symptom of a broadcast storm.
Recognizing flapping on a device
Most switches log flapping. The exact message varies by vendor. Cisco IOS-style switches produce messages that name the MAC address, the VLAN, and both ports, such as %SW_MATM-4-MACFLAP_NOTIF. The message tells you which two ports are involved, and that is the best starting point for finding the loop or duplicate.
Typical symptoms you see together with the log message:
- Intermittent connectivity for the affected host. Frames to it go to the wrong port about half the time.
- High CPU on switches, because of the flood of frames and constant table updates.
- Very high link utilization, near 100 percent, on the looped links.
- Many hosts losing connectivity at once, if a storm is in progress.
To check the table directly, run the inspection command twice a few seconds apart and compare the port for the suspect address. On a Linux bridge:
bridge fdb show br br0 | grep -i 00:00:00:00:00:0a
sleep 2
bridge fdb show br br0 | grep -i 00:00:00:00:00:0aIf the dev value differs between runs, the address is moving. On a Cisco IOS-style switch, show mac address-table address 0000.0000.000a gives the equivalent check.
Troubleshooting approach
Work from the evidence the switch gives you.
- Find the two ports. The flap log or repeated table checks show which ports alternate.
- Decide whether the address should be in two places. If it is a virtual MAC or a teamed server, check the failover or bonding configuration. A planned move is not a fault.
- Check for a loop. Look for unexpected redundant links, spanning tree state, and broadcast rates. If the same address flaps for many hosts, suspect a loop.
- Check for a duplicate. Trace each port to its device and compare the MAC addresses configured on them.
- Remove the cause, not the symptom. Clearing the table with a command only resets the entries. If the loop or duplicate remains, the entries flap again right away.
Protections against moves and duplicates
Some features restrict how moves are handled:
- Port security can limit the number of MAC addresses on a port, and it can mark certain addresses as sticky or static. If a protected address appears on another port, the switch can drop the frame or shut the port down. The next chapters cover this.
- Static entries pin an address to a port. A frame with that source on a different port does not overwrite the entry, and many switches report a violation.
- Move limits and loop detection are vendor features that detect rapid moves and block a port or send a warning.
These are deliberate exceptions to the default "last frame wins" behavior.
Exercise
A server with a shared virtual MAC address fails over from port 5 to port 9 once, and traffic resumes within a second. A different MAC address alternates between ports 2 and 3 about ten times per second, and CPU on the switch is high. Which case is normal, and what does the second case most likely indicate?
Show answer
The first case is a normal move. The switch overwrites the entry on the first frame from port 9, so traffic recovers without waiting for aging. The second case is MAC flapping, and the high CPU suggests a layer 2 loop or a broadcast storm between ports 2 and 3. A duplicate MAC address is also possible, but a rate of ten moves per second, together with high CPU, points to a loop. Check spanning tree state and the devices behind both ports.
Exercise
Using the LearningSwitch class, host A is learned on port 1 at time 0. A frame with source A arrives on port 2 at time 5. What does the table hold for A afterward, and which ports does a frame from B on port 3 to A reach at time 6?
Show answer
The table holds (2, 5), so the entry moved to port 2 with a fresh timer. The frame from B on port 3 to A is forwarded only to port 2, so the result is [2].