Bird
Raised Fist0
Linux CLIscripting~10 mins

ping for connectivity testing in Linux CLI - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - ping for connectivity testing
Start ping command
↓
Send ICMP Echo Request
↓
Wait for Echo Reply
↓
Receive Reply?
No→Timeout or Error
Yes↓
Display reply info
↓
Repeat or Stop
↓
End ping command
The ping command sends a small message to a target computer and waits for a reply to check if it is reachable.
Execution Sample
Linux CLI
ping -c 3 example.com
Send 3 ping requests to example.com and show the replies.
Execution Table
StepActionPacket NumberResultOutput
1Send ICMP Echo Request1Reply received64 bytes from example.com: icmp_seq=1 ttl=56 time=20 ms
2Send ICMP Echo Request2Reply received64 bytes from example.com: icmp_seq=2 ttl=56 time=21 ms
3Send ICMP Echo Request3Reply received64 bytes from example.com: icmp_seq=3 ttl=56 time=19 ms
4Summary--3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 19.000/20.000/21.000/0.816 ms
💡 All 3 packets received replies, ping command ends after sending 3 requests.
Variable Tracker
VariableStartAfter 1After 2After 3Final
packets_sent01233
packets_received01233
packet_loss_percent0%0%0%0%0%
Key Moments - 3 Insights
Why does ping send multiple packets instead of just one?
Sending multiple packets (see execution_table rows 1-3) helps check consistent connectivity and measure average response time.
What does it mean if no reply is received for a packet?
If no reply is received (not shown here), ping reports a timeout or packet loss, indicating possible network issues (see exit_note).
Why is the summary important at the end?
The summary (execution_table row 4) shows overall success, packet loss, and timing, giving a clear picture of network health.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, how many packets were sent before the ping command ended?
A3
B1
C0
D4
💡 Hint
Check the 'packets_sent' variable in variable_tracker after the final step.
At which step does the ping command show the summary of results?
AStep 1
BStep 3
CStep 4
DStep 2
💡 Hint
Look at the 'Action' column in execution_table for the summary row.
If the second packet did not receive a reply, how would 'packets_received' change after step 2?
AIt would be 2
BIt would be 1
CIt would be 0
DIt would be 3
💡 Hint
Refer to variable_tracker and consider what happens when a reply is missing.
Concept Snapshot
ping command sends ICMP echo requests to test if a host is reachable.
Use '-c' option to limit number of packets.
Each reply shows response time and packet info.
Summary shows packets sent, received, loss %, and timing.
No reply means possible network problem or host down.
Full Transcript
The ping command helps check if a computer or website is reachable by sending small messages called ICMP echo requests. Each request waits for a reply. If a reply comes back, it shows the time taken. The command usually sends multiple packets to check consistency. At the end, it summarizes how many packets were sent, how many replies were received, the percentage of lost packets, and timing details. If no reply is received, it may mean the target is offline or there is a network problem. This visual trace showed sending 3 packets to example.com, all replied successfully, and the summary confirmed 0% packet loss.

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