Concepts / Switches

Switches

MAC address table

Also called CAM table, forwarding database, fdb, bridge fdb, MAC learning, aging time, unknown unicast flooding

A switch's record of which port each MAC address was last seen on, learned from source addresses.

The problem

A switch cannot send a frame to one port until it knows which port that MAC is behind.

  1. The table starts empty. Alice pings bob; her frame comes in on the port alice.
  2. Learn: the switch notes her source MAC, b6:a0:12:30:a8:0b, behind alice.
  3. Flood: bob's MAC is not in the table yet, so the frame goes out of every other port, carol's too.
  4. Bob's reply comes in on bob: now both are learned, and every later frame is forwarded to one port only.
  5. Age: an entry not refreshed for the aging time (300 s by default) is forgotten.
Learn from the from, decide by the to
Learn from the from, decide by the to

Every frame teaches the switch one thing and asks it one thing. The source MAC fills the table, and the destination MAC is looked up in it. Only a miss, or a broadcast, goes out of every other port. From the Learning switches: how a box with no list finds every machine lab.

What you'd see

$ bridge fdb show br br0 dynamic
b6:a0:12:30:a8:0b dev alice master br0
06:c7:51:36:4e:b8 dev bob master br0
  • b6:a0:12:30:a8:0b dev alice: alice's MAC, behind the port alice.
  • 06:c7:51:36:4e:b8 dev bob: bob's, learned from his reply.
  • No line for carol: she has sent nothing, so the switch does not know where she is.

Guess first

The table is emptied and alice pings bob three times while carol records. How many of the pings does carol hear?

Show answer

One: the first request, flooded because bob was unknown. His reply teaches the switch his port, so the other requests go to bob alone.

In short

Four rules. Learn: a frame arriving on a port teaches the switch that its source MAC is behind that port. Forward: a frame whose destination is in the table leaves by that port only. Flood: a frame for an unknown destination, or a broadcast, leaves by every port but the one it came in on. Age: an entry not refreshed for the aging time (300 seconds by default) is forgotten. A device that has sent nothing is not in the table, and a device that moves is found again as soon as it sends. Entries typed in by hand (static) never age out.

See it on real machines

Read next

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Sign in with Google or email to start.

Start this lab