Sub topic 4
The MAC address table: what it stores
This chapter assumes you know what a MAC address is, how it differs from an IP address, and which fields an Ethernet frame carries (destination MAC, source MAC, EtherType). It also assumes you can tell a hub, a switch, and a router apart at a high level. The chapter covers the table's contents and structure. Later chapters cover how entries are created, refreshed, and removed.
Why the switch needs a table
A hub repeats every frame out of every other port. A switch avoids that by remembering which MAC address is reachable through which port. That memory is the MAC address table. It is also called the CAM table, the forwarding table, or on Linux the forwarding database (FDB).
The table is a lookup structure. Given a destination address, the switch must answer "which port?" quickly, at the line rate of every port at once. The rest of this chapter covers what the answer consists of, what the key is, and where the entries come from.
What one entry contains
An entry maps a lookup key to a port, plus some bookkeeping. Most switches store these fields:
| Field | Meaning | Example |
|---|---|---|
| VLAN ID | The VLAN the address was seen in. It is part of the lookup key. | 1, 20 |
| MAC address | The 48-bit address, written in hex. | 0011.2233.4455 |
| Port | The egress port, or a logical port such as a port channel or trunk. | Gi0/1 |
| Type | How the entry was created: dynamic (learned) or static (configured). | DYNAMIC |
| Age or last-seen time | When a frame from this address last arrived. The aging timer uses it. | 60 s |
Hardware tables may also hold flags, such as "drop frames to this address" or "this address belongs to the switch itself". The essential content is still a key (VLAN and MAC) and a port.
The key is VLAN plus MAC
The key is the pair (VLAN, MAC), not the MAC alone. A switch keeps a separate logical table per VLAN. The same MAC address can appear in two VLANs, with different ports, and the switch stores two independent entries. This follows from VLANs being separate broadcast domains. Per-VLAN learning gets its own chapter. For now, remember that the table has one row for each pair.
One MAC maps to one port
For a given key, the table holds one port. The table never records "this MAC is on ports 1 and 2". If a frame with that source arrives on a different port, the switch overwrites the port field (see the host-move chapter).
The reverse is allowed. Many MAC addresses can map to the same port. A port facing another switch, an access point, or a virtualization host will have many addresses behind it.
Only unicast source addresses are stored
The table stores addresses that identify a single device. Broadcast (ff:ff:ff:ff:ff:ff) and multicast addresses are group addresses and never appear as learned source addresses. A group address has the least significant bit of the first octet set, which is how a switch tells them apart. Frames sent to a group address are not looked up as unicast entries. The only multicast entries in the table are ones created by a multicast feature or by static configuration.
Dynamic and static entries
| Property | Dynamic | Static |
|---|---|---|
| Created by | Learning from frame source addresses | An administrator, or a feature such as port security |
| Removed by | Aging after inactivity, port-down events, topology changes, or a manual clear | Only by explicit configuration |
| Updated by | Every frame from the address, which refreshes its age | Not updated by traffic |
| Typical use | All ordinary end hosts | Servers, routers, or addresses you must pin to a port |
Dynamic entries make up almost all of a normal table. Static entries are covered in a later chapter. For now, note that a static entry has no age and is not displaced by learning.
A table you can run
This sketch models the table as a dictionary from (vlan, mac) to an entry. It is a data structure only, with no learning or forwarding logic yet.
from dataclasses import dataclass
@dataclass
class Entry:
port: int
last_seen: float
static: bool = False
table = {} # (vlan, mac) -> Entry
def install(vlan, mac, port, now, static=False):
table[(vlan, mac)] = Entry(port, now, static)
def show(now):
print("vlan mac type port age")
for (vlan, mac), e in sorted(table.items()):
kind = "STATIC" if e.static else "DYNAMIC"
age = "-" if e.static else int(now - e.last_seen)
print(vlan, mac, kind, e.port, age)
install(1, "00:11:22:33:44:55", 1, now=0)
install(1, "00:11:22:33:44:66", 2, now=10)
install(20, "00:11:22:33:44:55", 3, now=20) # same MAC, different VLAN
install(1, "00:11:22:33:44:ff", 4, now=0, static=True)
show(now=60)Running it prints:
vlan mac type port age
1 00:11:22:33:44:55 DYNAMIC 1 60
1 00:11:22:33:44:66 DYNAMIC 2 50
1 00:11:22:33:44:ff STATIC 4 -
20 00:11:22:33:44:55 DYNAMIC 3 40The address 00:11:22:33:44:55 appears twice, once in VLAN 1 on port 1 and once in VLAN 20 on port 3. These are two separate entries because the keys differ. The static entry shows - for age because it never expires.
How real hardware stores it
A software dictionary hides a hardware problem. A switch ASIC must find the entry for a destination in a few nanoseconds, for many frames in parallel. Two designs are common:
- CAM (content-addressable memory). The hardware compares the key against every stored entry at once and returns the match. This is where the name "CAM table" comes from. It is fast but costly in chip area and power, so the table is limited in size.
- Hash-based tables in SRAM. The key is hashed to a small set of buckets, and only those buckets are checked. This is cheaper and holds more entries. The trade-off is that hash collisions can fill a bucket before the table as a whole is full, so a new address may fail to be stored even when space remains elsewhere.
Software switches such as the Linux bridge use a kernel hash table. The effect is the same: a key goes in and a port comes out.
Capacity is finite
The table has a fixed maximum size. It ranges from a few thousand entries on small access switches to over a hundred thousand on large ones, depending on the model. Two consequences follow:
- When the table is full, the switch cannot learn new addresses. Frames to those addresses are flooded as unknown unicast, which wastes bandwidth and shows traffic to hosts that should not see it.
- An attacker can fill the table on purpose. That is the MAC flooding attack covered in a later chapter.
Aging is what normally keeps the table from filling with addresses of hosts that have gone quiet. The default aging time on Cisco IOS-style switches and on the Linux bridge is 300 seconds.
Reading the table on real devices
On an IOS-style switch, show mac address-table prints one row per entry. The columns correspond to the fields above: VLAN, address, type, and port.
Switch# show mac address-table
Mac Address Table
-------------------------------------------
Vlan Mac Address Type Ports
---- ----------- -------- -----
1 0011.2233.4455 DYNAMIC Gi0/1
1 0011.2233.4466 DYNAMIC Gi0/2
Total Mac Addresses for this criterion: 2
Switch# show mac address-table aging-timeOn a Linux bridge, the forwarding database is shown with the bridge tool:
bridge fdb show br br0Each line gives a MAC address and the port (dev) it was learned on. Flags such as permanent mark static entries, and vlan appears when VLAN filtering is enabled. A Linux bridge also lists entries for its own ports' addresses, flagged permanent or self. These are not learned from the network.
Common mistakes
- Treating the table as a list of MAC addresses. The key includes the VLAN, so the same address can legitimately appear more than once.
- Expecting one MAC to appear on two ports at once. A stable table has one port per key. A key that keeps switching ports points to a loop or a moving host.
- Assuming the table holds routes. It holds only Layer 2 reachability within a VLAN. It says nothing about IP networks.
Exercise
A switch shows 00:11:22:33:44:55 on port 1 in VLAN 1 and on port 3 in VLAN 20. Is this a fault? How many entries does the table hold for this address?
Show answer
It is not a fault. The key is the pair (VLAN, MAC), so the table holds two separate entries for this address, one per VLAN. A fault would be the same MAC in the same VLAN switching between ports repeatedly.
Exercise
Name two reasons a hardware switch might fail to learn a new address even though the table looks only partly full, and name what happens to frames sent to that address.
Show answer
The table may be full, or a hash-based table may have a full bucket for that key (a hash collision). Frames sent to the unlearned address are flooded as unknown unicast.