The ping Command — Network Connectivity Testing
Last Updated: 2025-01-01
3 min read
Overview
ping is the most basic network diagnostic tool. It sends small packets (ICMP echo requests) to a target host and measures the response time. Use it to check whether a server is reachable and to measure network latency.
Basic Syntax
ping [options] hostname_or_IP
Common Usage
Ping a host
ping example.com
On Linux, this runs continuously until you press Ctrl+C. Sample output:
PING example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.2 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=10.8 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=11.5 ms
^C
--- example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 10.800/11.166/11.500/0.286 ms
Send a specific number of pings
ping -c 5 example.com
The -c flag limits the number of packets sent. The command exits automatically after 5 pings.
Understanding the Output
Per-packet line
| Field | Meaning |
|---|---|
64 bytes | Size of the response packet |
icmp_seq=1 | Sequence number (tracks packet order) |
ttl=56 | Time to live — remaining hop count |
time=11.2 ms | Round-trip time (latency) in milliseconds |
Summary statistics
| Metric | Meaning |
|---|---|
| packets transmitted | How many pings were sent |
| received | How many responses came back |
| packet loss | Percentage of packets that never returned |
| rtt min/avg/max/mdev | Round-trip time: minimum, average, maximum, and standard deviation |
What the results mean
| Result | Interpretation |
|---|---|
| Low latency (< 50ms) | Good connection |
| High latency (> 200ms) | Slow connection, possibly distant server or congestion |
| 0% packet loss | Stable connection |
| Partial packet loss | Intermittent connectivity issue |
| 100% packet loss | Host unreachable, down, or blocking ICMP |
| “Request timed out” | No response received within the timeout |
Useful Flags
| Flag | Description |
|---|---|
-c N | Send N packets then stop |
-i N | Wait N seconds between pings (default: 1) |
-W N | Timeout in seconds for each response |
-s SIZE | Set packet size in bytes (default: 56) |
-q | Quiet mode — only show summary |
-f | Flood ping (requires root) — sends packets as fast as possible |
-4 | Force IPv4 |
-6 | Force IPv6 |
IPv6 Testing with ping6
To test IPv6 connectivity:
ping -6 example.com
# or on older systems:
ping6 example.com
Practical Examples
Quick connectivity check
ping -c 4 yourdomain.com
Check if DNS is working (ping an IP vs. a domain)
ping -c 3 8.8.8.8 # Google's DNS IP — tests raw connectivity
ping -c 3 google.com # Tests connectivity AND DNS resolution
If the IP works but the domain doesn’t, you have a DNS issue.
Test with a larger packet size
ping -c 5 -s 1400 example.com
Useful for detecting MTU (Maximum Transmission Unit) issues.
Troubleshooting Tips
- 100% packet loss doesn’t always mean the host is down — many servers and firewalls block ICMP (ping) traffic for security reasons.
- If ping fails but your website loads, ICMP is likely blocked — this is normal.
- Use
tracerouteormtrfor more detailed path analysis when ping shows high latency or packet loss. - Compare pings from your local machine to pings from the server itself to isolate whether the issue is on the network path or on the server.
Tags:
ssh
linux
ping
networking
diagnostics