How can I ping a specific IP on a network which only contain switches while switches as far as I know don't understand IPs but only MAC!
You are correct the switch only knows/cares about the MAC.
When you send a ping, host#1 first generates a arp asking for the MAC of a specific ip_dst(host#2) with a MAC_dst(ffff.ffff.ffff),MAC_src(Host#1) broadcast that the switch then forwards to all ports .
Once the destination host#2 receives the broadcast, the host#2 will see that it is a ARP for it's own IP(host#2), and using the MAC from the received packet, reply back to the original host#1, using known MAC's as src(Host#2) and dst(Host#1).
Once the host#1 receives the ARP reply back, it has the MAC(host#2) and will cache the mapping of IP-MAC in the ARP table, it then send's the rest of the packet e.g. ping's using the destination MAC_dst(host#2).
The switches don't care that it is a ping or any other packet type it only uses the MAC_dst.
It might be helpful for you to start a packet trace (with something like wireshark) you will see that the first thing your local machine does when you issue the ping command is broadcast an APR packet (assuming it isn't already in the arp table) to the IP address you are trying to reach. Example:
- IntelCor_00:00:88 Broadcast ARP 42 Who has 10.1.0.1? Tell 10.1.0.2
Once your local machine has the MAC address of the device your trying to reach it then assembles an ICMP (ping) packet with the destination MAC/IP combination. So your correct that the destination packet is a particular IP but that packet is then wrapped in a MAC frame and sent.
Hope that helps.