Bird
Raised Fist0
Linux CLIscripting~5 mins

ping for connectivity testing in Linux CLI - Commands & Configuration

Choose your learning style10 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.

Practice

(1/5)
1. What does the ping command do in Linux?
easy
A. Displays the current directory contents
B. Checks if your computer can reach another device on the network
C. Deletes files from the system
D. Installs new software packages

Solution

  1. Step 1: Understand the purpose of ping

    The ping command sends small packets to another device to check if it is reachable on the network.
  2. Step 2: Compare options

    Only Checks if your computer can reach another device on the network describes this network connectivity check. Other options describe unrelated commands.
  3. Final Answer:

    Checks if your computer can reach another device on the network -> Option B
  4. Quick Check:

    Ping = Network reachability check [OK]
Hint: Ping tests connection by sending packets [OK]
Common Mistakes:
  • Confusing ping with file or directory commands
  • Thinking ping installs software
  • Assuming ping deletes files
2. Which of the following is the correct syntax to send exactly 4 ping requests to example.com?
easy
A. ping example.com -c4
B. ping -n 4 example.com
C. ping -c 4 example.com
D. ping example.com -count 4

Solution

  1. Step 1: Recall the option to limit ping count

    The -c option followed by a number limits the number of ping requests sent.
  2. Step 2: Check each option

    ping -c 4 example.com uses -c 4 correctly. ping -n 4 example.com uses -n which is Windows syntax. ping example.com -count 4 uses incorrect syntax. ping example.com -c4 misses a space between -c and 4.
  3. Final Answer:

    ping -c 4 example.com -> Option C
  4. Quick Check:

    Use -c for count in Linux ping [OK]
Hint: Use '-c' to set ping count in Linux [OK]
Common Mistakes:
  • Using Windows ping options like -n
  • Missing space between option and number
  • Using incorrect option names
3. What will be the output of the command ping -c 2 127.0.0.1?
medium
A. Two ping requests sent to the local machine with reply times
B. Error: Unknown host 127.0.0.1
C. Ping command runs indefinitely
D. No output, command silently exits

Solution

  1. Step 1: Understand the IP address 127.0.0.1

    This IP is the loopback address, meaning the local machine itself.
  2. Step 2: Analyze the command with '-c 2'

    The command sends exactly 2 ping requests to the local machine and shows reply times.
  3. Final Answer:

    Two ping requests sent to the local machine with reply times -> Option A
  4. Quick Check:

    Ping 127.0.0.1 sends replies locally [OK]
Hint: 127.0.0.1 is local machine, ping replies shown [OK]
Common Mistakes:
  • Thinking 127.0.0.1 is unreachable
  • Expecting infinite ping without -c
  • Assuming no output is normal
4. You run ping -c 3 google.com but get the error: ping: unknown option -c. What is the likely cause?
medium
A. You are using a Windows command prompt instead of Linux terminal
B. The domain google.com does not exist
C. You forgot to add the IP address
D. The ping command is missing from your system

Solution

  1. Step 1: Understand the error message

    The error says '-c' is unknown, which is not typical in Linux but common in Windows ping.
  2. Step 2: Identify environment mismatch

    Windows ping uses '-n' for count, so running Linux-style ping with '-c' in Windows causes this error.
  3. Final Answer:

    You are using a Windows command prompt instead of Linux terminal -> Option A
  4. Quick Check:

    Windows ping uses -n, Linux uses -c [OK]
Hint: Windows ping uses -n, Linux uses -c [OK]
Common Mistakes:
  • Assuming domain name error
  • Thinking IP address is mandatory
  • Believing ping command is missing
5. You want to write a script that pings a server once and checks if it is reachable. Which command correctly pings 192.168.1.1 once and returns success if reachable?
hard
A. ping -c 1 192.168.1.1; echo 'Server reachable'
B. ping 192.168.1.1 -c 1 || echo 'Server reachable'
C. ping -n 1 192.168.1.1 && echo 'Server reachable'
D. ping -c 1 192.168.1.1 && echo 'Server reachable'

Solution

  1. Step 1: Use correct ping syntax for one request

    The -c 1 option sends exactly one ping request in Linux.
  2. Step 2: Use logical AND to echo only if ping succeeds

    The && operator runs the echo command only if ping returns success (reachable).
  3. Step 3: Analyze other options

    ping 192.168.1.1 -c 1 || echo 'Server reachable' uses || which runs echo on failure, not success. ping -n 1 192.168.1.1 && echo 'Server reachable' uses Windows syntax -n. ping -c 1 192.168.1.1; echo 'Server reachable' always echoes regardless of ping result.
  4. Final Answer:

    ping -c 1 192.168.1.1 && echo 'Server reachable' -> Option D
  5. Quick Check:

    Use -c 1 and && for success check [OK]
Hint: Use '-c 1' and '&&' to confirm ping success [OK]
Common Mistakes:
  • Using Windows ping options in Linux
  • Using '||' instead of '&&' for success
  • Echoing message regardless of ping result
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard