What is Ping?
Ping is a network utility used to test the reachability of a host on an IP network and measure the round-trip time for messages sent from the source to the destination. It works by sending ICMP (Internet Control Message Protocol) Echo Request packets and waiting for Echo Reply packets.
Example 1
Basic Ping Test
ping google.com
PING google.com (142.250.185.46): 56 data bytes
64 bytes from 142.250.185.46: icmp_seq=0 ttl=117 time=12.3 ms
64 bytes from 142.250.185.46: icmp_seq=1 ttl=117 time=11.8 ms
64 bytes from 142.250.185.46: icmp_seq=2 ttl=117 time=12.1 ms
Purpose: Test basic connectivity to a remote host.
Details: Sends continuous ICMP packets until manually stopped with Ctrl+C.
Output Explained:
Details: Sends continuous ICMP packets until manually stopped with Ctrl+C.
Output Explained:
64 bytes: Size of the packeticmp_seq: Sequence number of the packetttl: Time To Live (hops remaining)time: Round-trip time in milliseconds
Tip: Press Ctrl+C to stop the continuous ping and see statistics.
Example 2
Ping with Limited Count
ping -c 5 google.com
Purpose: Send a specific number of ping requests and then stop automatically.
Flag:
Use Case: Quick connectivity check without manual interruption, perfect for scripts.
Flag:
-c 5 sends exactly 5 packets then exits.Use Case: Quick connectivity check without manual interruption, perfect for scripts.
Windows Equivalent:
ping -n 5 google.com
Example 3
Ping with Custom Interval
ping -i 2 google.com
Purpose: Change the interval between sending packets.
Flag:
Use Cases:
Flag:
-i 2 waits 2 seconds between each packet (default is 1 second).Use Cases:
- Reduce network load during testing
- Monitor connections over longer periods
- Avoid triggering rate limits or security systems
Note: Values less than 0.2 seconds require root privileges.
Example 4
Flood Ping (Performance Test)
sudo ping -f google.com
Purpose: Send packets as fast as possible to test network performance.
Flag:
Output: Shows dots for sent packets and backspaces for received replies.
Warning: This generates significant network traffic and should only be used on networks you own or have permission to test.
Flag:
-f enables flood mode (requires root/sudo).Output: Shows dots for sent packets and backspaces for received replies.
Warning: This generates significant network traffic and should only be used on networks you own or have permission to test.
Caution: Can be considered a DoS attack if used improperly. Use responsibly!
Example 5
Ping with Custom Packet Size
ping -s 1000 google.com
Purpose: Send packets of a specific size in bytes.
Flag:
Use Cases:
Flag:
-s 1000 sends 1000-byte packets (default is 56 bytes).Use Cases:
- Test MTU (Maximum Transmission Unit) settings
- Identify packet fragmentation issues
- Test network behavior with larger payloads
Tip: Maximum size is typically 65507 bytes. Use
-M do flag to prevent fragmentation.
Example 6
Ping Only IPv4
ping -4 google.com
Purpose: Force ping to use IPv4 addresses only.
Flag:
Alternative: Use
Use Case: Troubleshoot IPv4/IPv6 connectivity issues separately.
Flag:
-4 restricts resolution and pinging to IPv4.Alternative: Use
-6 to force IPv6 only.Use Case: Troubleshoot IPv4/IPv6 connectivity issues separately.
Example 7
Ping with Timestamp
ping -D google.com
PING google.com (142.250.185.46): 56 data bytes
[1697552341.123456] 64 bytes from 142.250.185.46: icmp_seq=0 ttl=117 time=12.3 ms
[1697552342.234567] 64 bytes from 142.250.185.46: icmp_seq=1 ttl=117 time=11.8 ms
Purpose: Print timestamp (Unix time) before each line.
Flag:
Use Case: Log ping results with precise timing for analysis, debugging intermittent issues.
Flag:
-D adds timestamps in Unix epoch format.Use Case: Log ping results with precise timing for analysis, debugging intermittent issues.
Example 8
Ping with Audible Alert
ping -a google.com
Purpose: Produce an audible beep when a packet is received.
Flag:
Use Cases:
Flag:
-a enables audible ping.Use Cases:
- Monitor connection restoration without watching screen
- Alert when a previously unreachable host comes online
- Background network monitoring
Note: Requires system sound/beep to be enabled.
Example 9
Ping with Timeout
ping -W 2 -c 4 google.com
Purpose: Set a timeout for waiting for a response.
Flags:
Flags:
-W 2: Wait maximum 2 seconds for each reply-c 4: Send 4 packets total
Example 10
Ping with TTL (Time To Live) Setting
ping -t 10 google.com
Purpose: Set the Time To Live (TTL) value for packets.
Flag:
Explanation: Each router/hop decrements TTL by 1. When TTL reaches 0, the packet is discarded and an ICMP "Time Exceeded" message is returned.
Use Cases:
Flag:
-t 10 sets TTL to 10 hops.Explanation: Each router/hop decrements TTL by 1. When TTL reaches 0, the packet is discarded and an ICMP "Time Exceeded" message is returned.
Use Cases:
- Test network path length and routing
- Identify routing loops
- Understand network topology
- Similar to traceroute functionality
Related Tool: For detailed hop-by-hop analysis, use
traceroute or tracepath.
Bonus
Combination Example: Complete Network Test
ping -c 10 -i 0.5 -s 64 -W 1 -D google.com
Purpose: Comprehensive network test combining multiple options.
Combined Flags:
Combined Flags:
-c 10: Send exactly 10 packets-i 0.5: Wait 0.5 seconds between packets-s 64: Use 64-byte packet size-W 1: 1-second timeout per reply-D: Include timestamps