Switch MAC Address Learning – Default Router ARP

arpmac addressswitch

I know that switches learn MAC addresses of connected devices on their own by ARP and ARP Reply messages.

Can a newly started switch learn the MAC address of default router on its own by ARP, or do we have to configure it?

Please shed some light on how a device learns about default gateway in a network (network has a Device connected to switch, switch connected to default router only) where every device is new, does not have any information about other devices.

Best Answer

Switches don't use ARP to learn MAC addresses. Switches lean which MAC address is on which port simply by inspecting the source addresses on frames which come into the switch ports.

Switches don't understand layer-3 (except for layer-3 switches). To the switch, a router is just another host on the LAN.

All the above is from the perspective of layer-2 switch operation. A switch may have a management address, but, again, this is just another host on the LAN, and the management will use ARP and have a configured gateway and learn its MAC address with ARP, but it really has nothing to do with how the switching operates.

A host wishing to send an IP packet to another host will look in its ARP cache for the MAC address. If there isn't an entry in its ARP cache, it will send an ARP request to resolve the layer-3 IP address to the layer-2 MAC address. It will then build a layer-2 frame with this information and send it to the switch. If the destination IP address is on a different network, the host will look for the MAC address of its configured gateway in its ARP cache, and send an ARP request if it isn't in there, build a frame and send it out, just as it would for any other host.

As the frames come into the switch, the switch will look at the source MAC addresses, and use that to build its MAC address table, not the same as an ARP cache. When a switch receives a frame with a destination MAC address which isn't in its MAC address table, it will flood the frame out every port; it does not use ARP requests to discover this. It doesn't take a switch very long to build its MAC table since it take only one frame from each host to populate the MAC address table.