Lessons · Network switches · MAC ageing
The table forgets on purpose
A MAC address table entry is erased after a few minutes of silence from that address -- 300 seconds by default on a Cisco switch -- and learned again the instant the device speaks.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
Forgetting sounds like a flaw and is the feature. A laptop unplugged from one desk and plugged in at another would otherwise have its traffic sent to the port it left, for ever, until somebody cleared the table by hand.
How to think about it
Read an entry as 'this address was heard here recently', never as 'this device lives here'. The table is a record of what has been said lately, which is why it is right about a building that changes and would be wrong about one that does not.
Worked example
enableThe # prompt.
show mac address-tableEmpty, on a switch with nothing plugged in, and that is the lesson in one screen: the table holds what has been HEARD, so silence means no entry rather than no device.
configure terminalSwitch(config)#.
interface gi0/5Switch(config-if)#.
shutdownThe port goes down. On a real switch this is the moment the addresses learned there stop being true.
no shutdownAnd back up. Nothing is relearned until something on the far end speaks, which is exactly what ageing does on a slower clock.
endSwitch#.
show mac address-tableStill what has been heard, not what is connected. A device that has said nothing since it was last aged out is simply not here yet.
Your turn
Show every address this switch has learned.
show address-table
Console into a switch
The trap
Reading an empty table as a broken switch. A port with nothing plugged in, or a device that has not spoken since it aged out, is simply not in it. Make the device talk and look again.