Switch Learning – How Switch Learns MAC Addresses When Connected to a Router

routerswitch

Let's say we have a network like the one in the image below and the switches MAC tables are empty and the ARP tables are also empty. I want to send a packet from Host A to Host B. The question I want to ask is in what order and which MAC address the Switches learn?

Here is what i know till now:

Host 1 creates the packet with the Destination IP of Host B (172.30.2.16) and sends it.

Switch 1 gets the packet and looks up in his MAC Table (its empty) and then sends it to all of his ports (flood) and in meanwhile saves up the Source MAC of Host A in his MAC Table.

The packet comes to the Router which sends it to Switch 2. Now does the Switch 2 learns (saves) the Host A MAC address (caz its the source MAC) or it learns the Router MAC from which the packet came and its port is connected?

Now the Switch 2 floods all ports and gets positive answer from Host B and learns(saves) his MAC address in his table. Now the process is going in reverse to Host A.

Switch 1 MAC Table:

Port——Source MAC

1——Host A MAC

5——Router's MAC or is it Host B MAC ?

Switch 2 MAC Table:

Port——Source MAC

1——Host A MAC or Router's MAC ?

3——Host B
Netowrk

Thank you so much!

Best Answer

Each router replaces the Original source MAC address with the MAC adddress of the interface where the packet is going out of the router.

(in this case, the packet comes in through the red interface 
 and goes out on the brown interface).

So switch 2 and Host B learn the MAC address of the brown interface of the router.

They are unaware of the original MAC adddress, and they don't need to know it. When Host B needs to reply to Host Ait simply sends the packet to Host A IP address and Router's brown interface MAC.

Related Topic