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

Source: https://www.jpkc.com/db/en/cheatsheets/networking/ping/

<!-- PROSE:intro -->
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.
<!-- PROSE:intro:end -->

## Basic Usage

`ping HOST` — Ping a host continuously (until Ctrl+C). Shows RTT for each packet.

```bash
ping 8.8.8.8
```

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

```bash
ping google.com
```

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

```bash
ping -c 5 192.168.1.1
```

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

```bash
ping -c 10 -q 192.168.1.1
```

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

```bash
ping -c 3 -W 5 192.168.1.1
```

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

```bash
ping -w 10 192.168.1.1
```

## Timing & Interval

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

```bash
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.

```bash
sudo ping -f 192.168.1.1
```

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

```bash
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).

```bash
sudo ping -i 0.2 192.168.1.1
```

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

```bash
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).

```bash
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).

```bash
ping -s 1472 -M do 192.168.1.1
```

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

```bash
ping -t 10 8.8.8.8
```

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

```bash
ping -M do 192.168.1.1
```

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

```bash
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).

```bash
ping -p ff 192.168.1.1
```

## Interface & Source

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

```bash
ping -I eth0 192.168.1.1
```

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

```bash
ping -I 10.0.0.5 192.168.1.1
```

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

```bash
ping -S 10.0.0.5 192.168.1.1
```

## IPv6

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

```bash
ping -6 ::1
```

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

```bash
ping6 google.com
```

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

```bash
ping -6 -I eth0 fe80::1
```

## DNS & Name Resolution

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

```bash
ping -n 8.8.8.8
```

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

```bash
ping -a 192.168.1.1
```

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

```bash
ping -O 192.168.1.1
```

## Output & Statistics

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

```bash
ping -c 10 8.8.8.8 | tail -3
```

`ping -c 5 HOST 2>&1 | grep 'packet loss'` — Extract only the packet loss line.

```bash
ping -c 5 8.8.8.8 2>&1 | grep 'packet loss'
```

`ping -v HOST` — Verbose output. Show ICMP packets other than echo replies.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

```bash
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.

<!-- PROSE:outro -->
## 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](https://en.wikipedia.org/wiki/Ping_(networking_utility)) – background and history of the tool
- [ICMP – Wikipedia](https://en.wikipedia.org/wiki/Internet_Control_Message_Protocol) – the protocol that powers ping
- [ping(8) – Linux man page](https://linux.die.net/man/8/ping) – all options at a glance
<!-- PROSE:outro:end -->

## Related Commands

- [traceroute](https://www.jpkc.com/db/en/cheatsheets/networking/traceroute/) – trace the network path to a host hop by hop
- [mtr](https://www.jpkc.com/db/en/cheatsheets/networking/mtr/) – combines ping and traceroute for continuous path monitoring
- [dig](https://www.jpkc.com/db/en/cheatsheets/networking/dig/) – check DNS resolution before testing reachability

