ping — Test Network Reachability from the Command Line
Practical guide to ping — test network reachability, measure packet loss and round-trip time (RTT) via ICMP on the command line, with examples for every use case.
ping is the first tool you reach for when a host stops responding: a single command tests network reachability, measures round-trip time (RTT) and reveals packet loss. It sends ICMP Echo Request packets and evaluates the replies – from quick ad-hoc diagnostics and MTU path discovery to automated monitoring scripts. Available on every operating system, ping is the universal starting point for network troubleshooting.
Basic Usage
ping HOST — Ping a host continuously (until Ctrl+C). Shows RTT for each packet.
ping 8.8.8.8ping HOSTNAME — Ping a hostname. DNS resolution is performed first.
ping google.comping -c COUNT HOST — Send a specific number of packets and stop.
ping -c 5 192.168.1.1ping -c COUNT -q HOST — Quiet output — only show summary statistics at the end.
ping -c 10 -q 192.168.1.1ping -W TIMEOUT HOST — Set timeout in seconds for each reply. Useful for slow links.
ping -c 3 -W 5 192.168.1.1ping -w DEADLINE HOST — Stop after DEADLINE seconds regardless of packets sent/received.
ping -w 10 192.168.1.1Timing & Interval
ping -i INTERVAL HOST — Set the interval between packets in seconds (default: 1).
ping -i 0.5 192.168.1.1ping -f HOST — Flood ping — send packets as fast as possible. Requires root. Prints a dot per sent, backspace per received.
sudo ping -f 192.168.1.1ping -f -c COUNT HOST — Flood ping with a limited packet count.
sudo ping -f -c 1000 192.168.1.1ping -i 0.2 HOST — Fast ping with 200ms interval (requires root for intervals < 0.2s).
sudo ping -i 0.2 192.168.1.1ping -D HOST — Print a UNIX timestamp before each line.
ping -D 192.168.1.1Packet Size & TTL
ping -s SIZE HOST — Set the packet data size in bytes (default: 56, total ICMP: 64 with header).
ping -s 1000 192.168.1.1ping -s 1472 -M do HOST — Test Path MTU. Send 1472 bytes with do-not-fragment flag (1472 + 28 header = 1500 MTU).
ping -s 1472 -M do 192.168.1.1ping -t TTL HOST — Set the IP Time-To-Live value.
ping -t 10 8.8.8.8ping -M do HOST — Set the DF (Don't Fragment) bit. Useful for MTU discovery.
ping -M do 192.168.1.1ping -M dont HOST — Allow fragmentation (default).
ping -M dont 192.168.1.1ping -p PATTERN HOST — Fill the packet payload with a hex pattern (useful for diagnosing data-dependent issues).
ping -p ff 192.168.1.1Interface & Source
ping -I INTERFACE HOST — Use a specific network interface.
ping -I eth0 192.168.1.1ping -I SOURCE_IP HOST — Set a specific source IP address.
ping -I 10.0.0.5 192.168.1.1ping -S SOURCE_IP HOST — Set source address (alternative syntax on some systems).
ping -S 10.0.0.5 192.168.1.1IPv6
ping -6 HOST — Force IPv6 ping (ICMPv6).
ping -6 ::1ping6 HOST — IPv6 ping command (alias on many systems).
ping6 google.comping -6 -I INTERFACE HOST — Ping an IPv6 link-local address (requires interface specification).
ping -6 -I eth0 fe80::1DNS & Name Resolution
ping -n HOST — Numeric output only — do not resolve hostnames. Speeds up output.
ping -n 8.8.8.8ping -a HOST — Audible ping — beep on each received reply.
ping -a 192.168.1.1ping -O HOST — Report outstanding (unanswered) packets. Shows timeouts explicitly.
ping -O 192.168.1.1Output & Statistics
ping -c COUNT HOST | tail -3 — Show only the summary statistics.
ping -c 10 8.8.8.8 | tail -3ping -c 5 HOST 2>&1 | grep 'packet loss' — Extract only the packet loss line.
ping -c 5 8.8.8.8 2>&1 | grep 'packet loss'ping -v HOST — Verbose output. Show ICMP packets other than echo replies.
ping -v 192.168.1.1ping -c 1 -W 2 HOST > /dev/null 2>&1 && echo UP || echo DOWN — Quick one-liner to check if a host is reachable.
ping -c 1 -W 2 192.168.1.1 > /dev/null 2>&1 && echo UP || echo DOWNCommon Patterns
ping -c 100 HOST | tee ping.log — Ping and save output to a file while watching live.
ping -c 100 8.8.8.8 | tee ping.logfor h in HOST1 HOST2 HOST3; do ping -c 1 -W 1 $h && echo "$h OK" || echo "$h FAIL"; done — Ping multiple hosts and report status.
for h in 8.8.8.8 1.1.1.1 9.9.9.9; do ping -c 1 -W 1 $h > /dev/null 2>&1 && echo "$h OK" || echo "$h FAIL"; doneping -c 10 HOST | awk '/rtt/ {print $4}' | cut -d/ -f2 — Extract the average RTT from ping statistics.
ping -c 10 8.8.8.8 | awk '/rtt/ {print $4}' | cut -d/ -f2while ! ping -c 1 -W 1 HOST > /dev/null 2>&1; do sleep 1; done; echo 'Host is up!' — Wait until a host becomes reachable.
while ! ping -c 1 -W 1 192.168.1.1 > /dev/null 2>&1; do sleep 1; done; echo 'Host is up!'ping -c 4 -s 1472 -M do HOST — MTU path discovery: find the maximum packet size without fragmentation.
ping -c 4 -s 1472 -M do 192.168.1.1Reading ping Output
64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=12.3 ms — Normal reply: 64 bytes received, sequence number, TTL (hops remaining), round-trip time.
Request timeout / Destination Host Unreachable — No reply received. Host may be down, firewall blocking ICMP, or routing issue.
rtt min/avg/max/mdev = 10.1/12.5/15.3/1.8 ms — Summary statistics: minimum, average, maximum RTT, and standard deviation (jitter).
3 packets transmitted, 3 received, 0% packet loss — Packet loss summary. 0% = healthy connection, >5% = potential issue.
From 192.168.1.1 icmp_seq=1 Time to live exceeded — TTL expired in transit. The packet reached a router but TTL reached 0.
Conclusion
After decades, ping remains the first step in any network troubleshooting workflow: it quickly confirms reachability, surfaces packet loss, and measures latency. When you need deeper insight into the path a packet takes, reach for traceroute or mtr next.
Further Reading
- ping – Wikipedia – background and history of the tool
- ICMP – Wikipedia – the protocol that powers ping
- ping(8) – Linux man page – all options at a glance
Related Commands
- traceroute – trace the network path to a host hop by hop
- mtr – combines ping and traceroute for continuous path monitoring
- dig – check DNS resolution before testing reachability