How a Switch Routes Packets with Another Switch in Path

ethernetmac addressosiroutingswitch

I am just wondering how a switch does know how to route packets to destinations "hidden" behind another switch.
In my understanding a switch has a table that maps each of its hardware ports to exactly one MAC-address. So far so good, when a packet/frame (?) arrives it now can determine the port at which the packet should be routed.

But what happens when there is another switch connected to one of these ports and this second switch has more than one devices connected?

I am wondering how a switch is able to resolve this (on OSI-Layer 2, without a router), as I think this does indeed work in reality (?)

I am sorry if this question already exists (I think so, it should not be that uncommon), but I could not manage to put my thought into a suitable search query.

Best Answer

A Layer 2 switch learns most of its information about the location of other endpoints via "listening" to ingressing frames, and when it is not aware of the location, it uses floodingand will learn from the answer. Lets say the topology is:

(Host A) <--> (Switch A) <--> (Switch B) <-->(Host B).

Also important to note, a L2 Switch forwards, it does not route. By that I mean, when it receives an encapsulated frame, it forwards it out interfaces.

  • Host A wants to get to Host B. Host A knows Host B's MAC address. So Host A sends a frame out to Switch A.
  • Switch A does not have Host B in its MAC address Table. Switch A then flood out the frame on all of its ports, except for the one Host A is located. Among all those ports there is the ports that Switch B is plugged into, so Switch B receives the frame.
  • Switch B then flood that frame out all of its ports (considering Switch B does not have Host B in its MAC address Table).
  • Host B will respond to the frame, Switch B will then record Host B MAC address and send the response to Switch A. Switch A then records the MAC address of Host B in its table and send the response to Host A

Here's a related question: How does a switch learn a switch table?