Skip to content
Related Articles

Related Articles

Improve Article

How does a switch learn PC MAC Address before the PING process?

  • Last Updated : 07 Jun, 2021

The switch has some intelligence and its networking device operates in the Layer 2 Data link layer in the OSI model. Here, we will see how the switch learns the MAC address of an end device PC even before the PING process between Switch and PC. 

Let’s take an example of 2 PC’S connected to Switch.  Note: There are not assigned IP Addresses to PCs.

There is a switch in the middle and 2 PCs are connected to switch Ethernet ports. Both PCs have MAC addresses and the switch maintains the MAC address table, and it will learn all MAC addresses in the network.

Usually, the switch sends Layer 2 protocol frames like STP(Spanning-tree protocol), CDP(Cisco Discovery Protocol), and DTP(Dynamic Trunking Protocol)in periodic time intervals. These frames have a multi-cast destination MAC address, so these frames will be flooded to both PCs.



As you know, PC is a layer 3 device, and it has no service to accept Layer 2 protocol frames. So it will drop the frames and never send back a reply switch. So there is no chance of learning PC MAC address by a switch.

At this point, when we run the command in switch, then you will see no entry in the MAC address table.

 MAC Address table

Switch#show mac-address-table  
         Mac Address Table
-------------------------------------------

Vlan    Mac Address       Type        Ports
----    -----------       --------    -----

Suppose, assign IP address 192.168.0.1 255.255.255.0 to PC1. It immediately generates an ARP packet with broadcast destination mac address FFFF.FFFF.FFFF and destination IP address with its own IP address 192.168.0.1.

Also note that, in this packet, you can see the PC1 source MAC address and source IP address.

Since it’s a broadcast frame, it will be flooded to the network. The switch receives the packet, and it will learn the MAC address of the PC1, and it will update in the MAC address table.



Now, if you run the command in Switch, you will see PC1 MAC-address entry in MAC address table. 

MAC Address Table 

Switch#show mac-address-table  
         Mac Address Table
-------------------------------------------
Vlan    Mac Address       Type        Ports
----    -----------       --------    -----
  1    0007.ec7d.9e46    DYNAMIC     Fa0/1

PC2 also receives the packet, and it will check the destination MAC address first. Since it’s broadcast MAC address, it will accept and send to Layer 3. At layer 3, it will check the destination IP address. The destination IP address must be a PC2 IP address but here it has PC1 IP address, so it will drop the packet.

Thus switch learns PC MAC address even before the data traffic flow or PING process. 

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.

 

My Personal Notes arrow_drop_up
Recommended Articles
Page :