0
0
Linux CLIscripting~5 mins

ping for connectivity testing in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes you need to check if another computer or website is reachable from your computer. The ping command sends small messages to the other computer and waits for a reply to confirm the connection is working.
When you want to check if your internet connection is working by pinging a public website like google.com
When you want to see if a server on your local network is turned on and reachable
When you want to measure how long it takes for messages to travel between your computer and another device
When troubleshooting network problems to find out if a device is responding
When you want to check if a website is down or just unreachable from your location
Commands
This command sends 4 ping messages to google.com to check if it is reachable and shows the response time for each message.
Terminal
ping -c 4 google.com
Expected OutputExpected
PING google.com (142.250.190.78) 56(84) bytes of data. 64 bytes from lga34s10-in-f14.1e100.net (142.250.190.78): icmp_seq=1 ttl=117 time=14.2 ms 64 bytes from lga34s10-in-f14.1e100.net (142.250.190.78): icmp_seq=2 ttl=117 time=13.8 ms 64 bytes from lga34s10-in-f14.1e100.net (142.250.190.78): icmp_seq=3 ttl=117 time=14.0 ms 64 bytes from lga34s10-in-f14.1e100.net (142.250.190.78): icmp_seq=4 ttl=117 time=13.9 ms --- google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3004ms rtt min/avg/max/mdev = 13.812/14.004/14.237/0.160 ms
-c - Limits the number of ping messages sent
This command sends 3 ping messages to the local router at IP address 192.168.1.1 to check if it is reachable on the local network.
Terminal
ping -c 3 192.168.1.1
Expected OutputExpected
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=1.23 ms 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.10 ms 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=1.15 ms --- 192.168.1.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 1.102/1.161/1.234/0.054 ms
-c - Limits the number of ping messages sent
This command tries to ping a non-existent domain to show what happens when the destination cannot be reached.
Terminal
ping -c 2 example.invalid
Expected OutputExpected
ping: example.invalid: Name or service not known
-c - Limits the number of ping messages sent
Key Concept

If you remember nothing else from ping, remember: it sends small messages to check if another computer is reachable and measures the response time.

Common Mistakes
Running ping without the -c flag and letting it run forever
Ping will keep sending messages endlessly until you stop it manually, which can be confusing or waste resources
Always use -c with a number to limit how many messages ping sends
Trying to ping a hostname that does not exist or is misspelled
Ping will fail with a name resolution error because it cannot find the IP address
Double-check the hostname spelling or use a known reachable IP address
Ignoring packet loss or high response times in the ping output
Packet loss or slow responses indicate network problems that need attention
Use ping output to diagnose network issues and investigate if you see packet loss or high latency
Summary
Use ping with the -c flag to send a limited number of messages and check connectivity.
Ping shows if a device or website is reachable and how long messages take to travel.
Errors in ping usually mean the destination is unreachable or the name is wrong.