2

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.

3

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.

  • My bad. Switches use ARP messages of other devices in network to learn mac address. I still didn't get what i wanted. <br/> So if a switch is new and booted for the first time, when it gets packet from a host who wants to reach some IP address in internet, how does that switch knows how to send that packet to default router? – Vinnie Mar 16 '16 at 22:30
  • That's not exactly true. A switch will use any frame to build its MAC address table; it knows nothing about ARP since ARP is resolving layer-3 addresses to layer-2 addresses, and switches don't know anything about layer-3. Also, switches don't get packets, they get frames, and the switches know nothing about routers/gateways, that is up to the sending host. – Ron Maupin Mar 16 '16 at 22:34
  • You are confusing layer-2 (switching) with layer-3 (routing). Layer-2 frames encapsulate layer-3 packets, and the switches don't strip off the frame to look at the packet; routers do that. – Ron Maupin Mar 16 '16 at 22:36
  • As far as not answering your question, I did exactly that in the 4th paragraph of my answer: "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." – Ron Maupin Mar 16 '16 at 22:38
  • that is what i am not getting. How host gets mac address of gateways if mac address of gateway is not present in ARP cache? Can you explain this in details? Like what would be destination mac addresses and source mac addresses in all ARP and ARP Replies? – Vinnie Mar 17 '16 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.