Ping Issues in the Same Subnet – Troubleshooting Guide

ping

I understand that ping packet use layer the IP address of the destination.
but I do not understand how it works between 2 hosts residing in the same subnet and they are both connected to the same layer 2 switch

how does the layer 2 switch act when receiving the ping packet

enter image description here

thanks

Best Answer

On a directly connected layer-2 network/segment, IP communication works by encapsulating IP packets into layer-2 frames addressed to the destination's MAC. The source learns the destination's MAC address by using ARP (IPv4) or NDP (IPv6).

The switch doesn't see the IP packet within the Ethernet frame, but it looks at the frame's MAC addresses. The destination MAC address is used to select the egress switch port. The source MAC address is used to update the switch's MAC table.