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.8

ping HOSTNAME — Ping a hostname. DNS resolution is performed first.

ping google.com

ping -c COUNT HOST — Send a specific number of packets and stop.

ping -c 5 192.168.1.1

ping -c COUNT -q HOST — Quiet output — only show summary statistics at the end.

ping -c 10 -q 192.168.1.1

ping -W TIMEOUT HOST — Set timeout in seconds for each reply. Useful for slow links.

ping -c 3 -W 5 192.168.1.1

ping -w DEADLINE HOST — Stop after DEADLINE seconds regardless of packets sent/received.

ping -w 10 192.168.1.1

Timing & Interval

ping -i INTERVAL HOST — Set the interval between packets in seconds (default: 1).

ping -i 0.5 192.168.1.1

ping -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.1

ping -f -c COUNT HOST — Flood ping with a limited packet count.

sudo ping -f -c 1000 192.168.1.1

ping -i 0.2 HOST — Fast ping with 200ms interval (requires root for intervals < 0.2s).

sudo ping -i 0.2 192.168.1.1

ping -D HOST — Print a UNIX timestamp before each line.

ping -D 192.168.1.1

Packet 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.1

ping -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.1

ping -t TTL HOST — Set the IP Time-To-Live value.

ping -t 10 8.8.8.8

ping -M do HOST — Set the DF (Don't Fragment) bit. Useful for MTU discovery.

ping -M do 192.168.1.1

ping -M dont HOST — Allow fragmentation (default).

ping -M dont 192.168.1.1

ping -p PATTERN HOST — Fill the packet payload with a hex pattern (useful for diagnosing data-dependent issues).

ping -p ff 192.168.1.1

Interface & Source

ping -I INTERFACE HOST — Use a specific network interface.

ping -I eth0 192.168.1.1

ping -I SOURCE_IP HOST — Set a specific source IP address.

ping -I 10.0.0.5 192.168.1.1

ping -S SOURCE_IP HOST — Set source address (alternative syntax on some systems).

ping -S 10.0.0.5 192.168.1.1

IPv6

ping -6 HOST — Force IPv6 ping (ICMPv6).

ping -6 ::1

ping6 HOST — IPv6 ping command (alias on many systems).

ping6 google.com

ping -6 -I INTERFACE HOST — Ping an IPv6 link-local address (requires interface specification).

ping -6 -I eth0 fe80::1

DNS & Name Resolution

ping -n HOST — Numeric output only — do not resolve hostnames. Speeds up output.

ping -n 8.8.8.8

ping -a HOST — Audible ping — beep on each received reply.

ping -a 192.168.1.1

ping -O HOST — Report outstanding (unanswered) packets. Shows timeouts explicitly.

ping -O 192.168.1.1

Output & Statistics

ping -c COUNT HOST | tail -3 — Show only the summary statistics.

ping -c 10 8.8.8.8 | tail -3

ping -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.1

ping -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 DOWN

Common 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.log

for 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"; done

ping -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/ -f2

while ! 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.1

Reading 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

  • 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