Testing connectivity: ping
ping checks whether another machine is reachable and how long it takes to reply.
Syntax
ping [-c count] hostping is the first tool to reach for when the network seems broken. It sends small packets to a host and measures the round-trip time of the replies.
Reading the output
- time= — the round trip in milliseconds; lower is better.
- 0% packet loss — every packet returned; the link is healthy.
On Linux ping keeps going until you stop it with Ctrl+C. Use -c 4 to send just four packets and exit.
Example
# Send four packets then stop
ping -c 4 google.com
# 64 bytes from ...: time=12.3 ms
# 4 packets transmitted, 4 received, 0% packet loss
# Ping an IP address directly
ping -c 4 1.1.1.1When to use it
- A sysadmin runs 'ping -c 4 8.8.8.8' to verify internet connectivity after configuring a new server's network interface.
- A network engineer uses 'ping -i 0.2 -c 100 192.168.1.1' to measure packet loss on a LAN link over many rapid samples.
- A developer pings an internal service hostname to confirm DNS resolution is working before deploying an application.
More examples
Basic connectivity check
Uses -c 4 to send exactly 4 ICMP packets, avoiding an infinite ping, and reports round-trip time statistics.
# Send 4 packets then stop
ping -c 4 google.com
# PING google.com (142.250.80.46): 56 bytes
# 4 packets transmitted, 4 received, 0% packet loss
# rtt min/avg/max = 11.2/12.4/14.1 msPing with custom interval
Uses -i to set the interval between packets; -f enables flood mode for high-rate stress testing.
# Ping every 0.2 seconds for 20 packets
ping -i 0.2 -c 20 192.168.1.1
# Flood ping (requires root) for stress testing
sudo ping -f -c 1000 192.168.1.1Ping to check DNS and latency
Shows that ping implicitly tests DNS resolution and uses a loop to compare latency across multiple hosts.
# Ping resolves the hostname first, showing its IP
ping -c 2 api.example.com
# PING api.example.com (203.0.113.42): 56 bytes
# Compare latency to two endpoints
for host in api.example.com db.example.com; do
echo -n "$host: "
ping -c 3 -q "$host" | tail -1
done
Discussion