How does a switch communication map ip address to Mac address? [closed]

Assuming 10 computers are connected via hub. Pc1 sends data to ip address of pc2. But hub broadcasts it to all computers.

Whereas if I replace hub with switch, then switch will maintain table of switch plug and Mac address.

When PC1 sends data to PC2's ip address, then how does switch ensure that it is send to correct computer (Pc2)? I am asking because switch doesn't keep record of ip address.


Solution 1:

In a nutshell, a switch learns which MAC addresses are associated with which switch ports. A network host wishing to communicate with another network host resolves the ip address of the destination host to the MAC address of the destination host and addresses the communication (at the data link layer) to that MAC address. The switch sees the destination MAC address and forwards it to the appropriate switch port.