I've connected multiple PCs to a 2960 switch and then entered privilege mode and entered : show mac-address-table
but the table is empty. Then I pinged the broadcast address from one of the PCs: ping 192.168.1.255
and used the previous command on the switch once again and the mac address table lists all the PCs' mac addresses, I wonder if there is a shorter way? i.e. a command on switch to gather the mac addresses of the connected devices to its ports without the need to the pinging step? Thanks.
2 Answers
EDIT:
To actually answer the question: show mac-address-table
or show mac address-table
(depending on platform and software generation) is the single command to see the MAC address table on a Cisco Switch like the 2960. The fact that the table comes up empty is very probably correct.
Here's why:
MAC address tables (sometimes referred to as CAM tables) are usually dynamic, and their entries are aged out after a given timeout, usually 300 seconds.
An entry is added as soon as an Ethernet frame arrives on a switch port. It's source MAC address is kept and is added to the CAM table and its aging timer starts to decrement.
If connected devices stay silent for more than 300 sec (or the given CAM table aging value), their MAC addresses are removed from the CAM table.
If another device needs to talk to such a dormant peer, the switch will have to perform "unknown unicast flooding" and send the given Ethernet frame out of all ports (more precisely: all active/forwarding ports of the given VLAN). As soon as the device of interest responds with an Ethernet frame, the CAM table is (re)populated instantly with a new entry.
There can be more advanced setups with sticky or static CAM table entries, but that's another story.
This being said...
IF a constantly populated CAM table is a requirement, AND IF the connected devices have no need to be allowed to "sleep" for longer periods of time (for example to save energy), AND IF the scope of interesting devices/table entries covers IPv4 enabled devices, there is one trick that can help a lot without requiring a lot of advanced config:
Many routers (CEF enabled Cisco router definitely do it) do active maintenance of their ARP cache, but have a default ARP timeout of 4hours. By lowering their ARP timeout to some value lower than 300sec (which does little to no harm), the router will re-query the entries in its ARP cache, shortly before they expire. That will in turn trigger a response from the devices, and these ARP replies then keep the switch's CAM tables populated.
When network setup is new , initially mac -address table in switch will be empty because there are no request received by switch to forward frames towards destination no ARP flooding and no broadcast traffic to create mac-address table in switch . When a request reaches towards switch it's associated mac-address table is created .
To get full mac-address table connected on switch in some way traffic has to be initiated from source or towards destination so that mac -address table is built in switch .
ff02::1
in case there are devices which don't respond to192.168.1.255
. Of course it still won't guarantee to reach all devices, and there really isn't any way to force an unknown device to send a packet.