How Switch Learns MAC Address of Connected Devices to It in a LAN example using Packet tracer
In this post, we are going to see how the switch learns MAC(Media Access Control) address and how Switch makes forward , filter decision.
.Create a topology with switch and 5 PC connected to it,like below example.I have shown IP address and MAC(Hardware) address of each PC connected to switch.
PC1 is connected to Switch Port Fastethernet0/1 (Fa0/1)
PC2 is connected to Switch Port Fastethernet0/1 (Fa0/2)
PC3 is connected to Switch Port Fastethernet0/1 (Fa0/3)
PC4 is connected to Switch Port Fastethernet0/1 (Fa0/4)
PC5 is connected to Switch Port Fastethernet0/1 (Fa0/5)
.Initially there won't be any MAC address present in PC ARP Cache and Switch MAC address table.I am going to check ARP cache of PC2,PC5 and MAC address table of switch.
.I am going to check ARP cache of PC2,PC5 and MAC address table of switch.Give this command "arp -a" in command promt to check if any saved MAC address present in a PC ARP Cache.To check MAC address table of switch give this command in Privileged mode of the switch "show mac-address-table".Initially it won't have any MAC address present in it.
.Now, Ping from any PC in a LAN to any other PC connected to that switch.I'm going to ping PC5 from PC2, then we see what happens. Go to PC2 command prompt and give this command "ping 192.168.1.50".Now the device PC2 will send a echo request payload to PC5 or we can create a complex PDU.I am going to use complex PDU to show what will happen after we give ping commandand we have to select simulation mode in bottom right corner. Click on PC2 and select complex PDU, then a window will open. we have to give this details,
click on "Create PDU" and ckick on "Play" button.
PC will check ARP cache for the destination MAC address, if MAC address is not present ARP Packet will be sent from PC2 with,PC will check the subnet mask to findout the destination host IP is present in same network or different network.If destination IP present in different network,packet will be forwarded to default gateway.Here, the destination IP present in same network, so switch will broadcast throughout the LAN.
Source IP address - 192.168.1.20
Destination IP address- 192.168.1.50
Source MAC address - 0001.96DD.75DC
Destination MAC address- FFFF.FFFF.FFFF
Once the packet reached the switch, it will check received frames source hardware address and destination address.If the source hardware address not found in MAC Address table then, Switch will save the Source hardware address (MAC) to the MAC address table with port number information on which frames has been received.Here,Source MAC address is 0001.96DD.75DC this information will be saved to MAC address table, Check above image.
If the destination hardware address (MAC ) not present in MAC address table of switch , then switch will broadcast the frames through out all interface connected to it, Except the port in which the frame has been received.
.All Devices connected to this switch will get this frames and the devices will check destination hardware address "FFFFFFFFFFFF" it is broadcast address and it will check IP address of the received packet.If it not matched then it will drop the packet, if IP matched then Source MAC address of received frame will be saved to ARP cache and It will send a echo payload reply with its MAC address ,Only PC5 IP will get a match and it will send a reply to PC2. All other device will drop the frames.check above image.
Now PC5 will reply with its source MAC and IP address, Destination address as PC2 MAC Address and IP address.
Now,switch will receive frame from PC5 and it will check received frames source hardware address and destination address. If the source hardware address not found in MAC Address table then Switch will save the Source (MAC) hardware address 0060.5CAA.AA16 to the MAC address table with port number information on which frames has been received.
In this case PC2 hardware address already present in Switch MAC address table.So, switch will forward packet Only thorough FastEthernet0/2.Finally, it reaches PC2 with Source MAC address of PC5.PC2 will save the MAC address of PC5 in it's ARP Cache.
.Now, PC2 knows the MAC address for the IP address of 192.168.1.50. PC2 will send ICMP packets with Source MAC and IP of PC2 and destination address as PC5 MAC and IP.This time when the frames reaches switch, the switch will forward frames only on port FastEthernet0/5. Because the MAC address already present in MAC address table.
Once the frames reached PC5 .PC5 will send a reply.Once the switch learned MAC address then it won't broadcast again. It will send packet only on particular port on that destination device connected to it.