ping — quick reference
Basic reachability
Send ICMP echo requests and read replies — the first check when a host "does not respond."
| When to use | Command |
|---|---|
| Ping until you press Ctrl+C (default on most hosts) | ping destination |
| Send a fixed number of probes and stop | ping -c 4 destination |
| Ping the local stack (loopback) | ping -c 3 127.0.0.1ping -c 3 localhost |
| Skip reverse DNS — faster when you already have an IP | ping -n 203.0.113.10 |
| Force reverse DNS even for numeric addresses | ping -H 203.0.113.10 |
Timing and packet size
Control how often packets go out, how long to wait, and how large each probe is.
| When to use | Command |
|---|---|
| Wait N seconds between packets (default 1; minimum 0.2 for non-root) | ping -i 0.5 destination |
Stop after N seconds total (deadline) regardless of count |
ping -w 10 destination |
Wait up to N seconds for each reply (timeout) |
ping -W 2 destination |
| Change ICMP data payload size in bytes (default 56 → 64 bytes on the wire with header) | ping -s 100 destination |
| Set IP time-to-live (hop limit) | ping -t 32 destination |
Output control
Trim noise for scripts or add detail for troubleshooting.
| When to use | Command |
|---|---|
| Print only start and summary lines | ping -q -c 5 destination |
| Prefix each reply line with a Unix timestamp | ping -D -c 3 destination |
| Beep on each reply (if terminal supports it) | ping -a -c 3 destination |
| Report outstanding replies before the next packet | ping -O -c 3 destination |
| Verbose ICMP errors | ping -v destination |
Address family and interface
Pick IPv4 or IPv6 explicitly, or bind to one network interface.
| When to use | Command |
|---|---|
| Force IPv4 | ping -4 destination |
| Force IPv6 | ping -6 destination |
| Send probes out a specific interface | ping -I eth0 destination |
Flood and diagnostics
High-rate probes and timestamp options — flood mode needs root.
| When to use | Command |
|---|---|
Flood ping (root only; prints . per send) |
sudo ping -f destination |
| Preload N packets while waiting for replies (root if N > 3) | ping -l 5 -c 10 destination |
IPv4 timestamp option (tsonly, tsandaddr, or tsprespec) |
ping -T tsonly -c 2 destination |
| Print user-to-user latency (includes DNS time) | ping -U -c 3 destination |
Help and version
| When to use | Command |
|---|---|
| Show built-in usage | ping -h |
| Show iputils version | ping -V |
ping — command syntax
Synopsis from ping -h on Ubuntu 25.04 (iputils ping 20240905):
ping [options] <destination>destination is a hostname or IP address. ping uses raw ICMP sockets and does not modify system config files. Flood ping (-f) and high preload values need root or sudo.
ping — command examples
Essential Ping localhost with a fixed count
Check that the network stack responds on the loopback interface — a quick sanity check before testing remote hosts.
Run the command:
ping -c 3 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.087 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.047 ms
--- 127.0.0.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2084ms
rtt min/avg/max/mdev = 0.034/0.056/0.087/0.022 ms0% packet loss and reply lines mean ICMP echo replies reached your machine. RTT is round-trip time in milliseconds.
Essential Quiet mode — summary only for scripts
Use -q when you only care about the statistics line, not every reply — handy in cron jobs or health checks.
Run the command:
ping -q -c 2 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1015ms
rtt min/avg/max/mdev = 0.035/0.040/0.045/0.005 msIn scripts, check the exit code: 0 means at least one reply arrived; 1 or 2 means total loss or another error.
Essential Unreachable host — 100% packet loss
When a host blocks ICMP or is down, ping still exits after the timeout — you see zero replies and non-zero packet loss.
Run the command (TEST-NET-1 address — documentation block, should not respond):
ping -c 1 -W 1 192.0.2.1Sample output:
PING 192.0.2.1 (192.0.2.1) 56(84) bytes of data.
--- 192.0.2.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms100% loss does not always mean the host is down — many firewalls drop ICMP. For a service that listens on TCP, use port connectivity tests next.
Common Custom interval and packet size
Slow down probes with -i or enlarge the payload with -s when you are testing MTU-related issues or rate limits.
Run the command:
ping -c 2 -i 0.5 -s 100 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 100(128) bytes of data.
108 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.029 ms
108 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.051 ms
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 502ms
rtt min/avg/max/mdev = 0.029/0.040/0.051/0.011 msThe reply line shows 100(128) — 100 bytes of data plus 8-byte ICMP header and 20-byte IP header on the wire. Non-root users cannot set -i below 0.2 seconds.
Common -4 with an IPv6 address fails fast
Mixing address family flags and literal addresses produces a clear error before any packets are sent.
Run the command:
ping -c 1 -4 ::1Sample output:
ping: ::1: Address family for hostname not supportedUse -6 for IPv6 literals and -4 for IPv4. Omit both when the resolver returns the family you want.
Common Deadline (-w) vs per-reply timeout (-W)
-w caps total runtime; -W limits how long ping waits for each individual reply. Combine them with -c for predictable script behaviour.
Run the command:
ping -c 2 -w 5 -W 1 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.046 ms
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1027ms
rtt min/avg/max/mdev = 0.033/0.039/0.046/0.006 msOn a silent host, -W 1 stops waiting for each reply after one second; -w 10 stops the whole run after ten seconds even if -c was higher.
Common Print a timestamp before each reply line
-D helps correlate ping output with logs when you are chasing intermittent latency.
Run the command:
ping -D -c 2 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
[1782900331.089131] 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.023 ms
[1782900332.107642] 64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.036 ms
--- 127.0.0.1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1011ms
rtt min/avg/max/mdev = 0.023/0.029/0.036/0.006 msPair -D with -O when you want timestamps and outstanding-reply reporting in one log file.
Advanced Set TTL to trace hop limits
Lowering TTL makes the probe die after N hops — useful with traceroute style debugging. On loopback, TTL 1 still works because the target is local.
Run the command:
ping -c 1 -t 1 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 ms
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.034/0.034/0.034/0.000 msToward a remote host, ttl=1 often yields Time to live exceeded from the first router instead of an echo reply.
Advanced IPv4 timestamp option (-T tsonly)
-T requests IP timestamp options on IPv4 probes — mainly for low-level network debugging.
Run the command:
ping -c 1 -T tsonly 127.0.0.1Sample output:
PING 127.0.0.1 (127.0.0.1) 56(124) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.051 ms
TS: 36412827 absolute
0
0
--- 127.0.0.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.051/0.051/0.051/0.000 msThe TS: block is the timestamp option payload. Many networks strip or ignore these options — expect mixed support on the public internet.
ping — when to use / when not
| Use ping when | Use something else when |
|---|---|
|
|
ping vs traceroute
Both use ICMP (or similar probes), but they answer different questions.
| ping | traceroute | |
|---|---|---|
| Question | Is the destination reachable? What is RTT? | Which routers sit on the path? Where does the path stop? |
| Output | Repeated replies from the target | One line per hop |
| Best for | Up/down checks, latency | Path debugging, asymmetric routing |
Use ping first; switch to traceroute when the host is reachable but behaviour is slow or intermittent.
Related commands
Commands often used in the same network troubleshooting workflow.
| Command | One line |
|---|---|
| ping | ICMP reachability and RTT (this page) |
Browse the full index in our Linux commands reference.
ping — interview corner
What does the ping command do in Linux?
ping sends ICMP echo request packets to a destination host and waits for echo replies. Each reply line shows sequence number, TTL, and round-trip time.
ping -c 2 127.0.0.1Sample output:
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.034 msIt answers layer-3 reachability — not whether a web server on port 443 is healthy.
A strong answer is:
"ping sends ICMP echo requests and reports replies, RTT, and packet loss. I use it for basic host reachability before port or HTTP checks."
What exit code does ping return?
On iputils ping, exit code 0 means at least one reply was received. 1 usually means 100% packet loss. 2 indicates a usage or other error.
Scripts often combine -c (fixed count), -W (per-reply timeout), and the exit code:
ping -c 1 -W 2 203.0.113.10 && echo up || echo downA strong answer is:
"Exit 0 when any reply arrives, 1 on total loss, 2 on errors — I rely on exit codes in scripts with -c and -W."
Can ping prove a web server is working?
No. ping only tests ICMP. A host can block ICMP while HTTP on port 80 or 443 works fine — or the host can answer ping while the application is down.
Use curl or a port check for service-level tests.
A strong answer is:
"No — ping is ICMP only. I use curl or nc for service ports when ICMP is blocked or irrelevant."
What is the difference between ping -c and ping -w?
-c stops after sending (and ideally receiving) that many probes. -w sets a deadline in seconds — ping exits when the deadline is hit even if -c was not reached.
ping -c 100 -w 5 destination # stops at 5 seconds OR 100 replies, whichever comes firstA strong answer is:
"-c is a probe count; -w is a total time budget. I combine both in scripts so runs cannot hang forever."
Why does ping fail when the host is up?
Common causes: firewall drops ICMP, wrong address family (-4 vs -6), DNS failure, or routing to the subnet is missing. The host OS can be healthy while ICMP is filtered.
A strong answer is:
"ICMP is often filtered. I confirm with traceroute or a TCP port test, and check -4/-6 and DNS separately."
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Address family for hostname not supported |
-4 with IPv6 literal (or the reverse) |
Match flag to address type or drop -4/-6 |
ping: socktype: SOCK_RAW / permission errors |
Non-root raw socket restrictions on some systems | Run with appropriate capabilities or use an unprivileged ping build if available |
| Hangs until Ctrl+C | No -c or -w on a silent host |
Add -c N and -W timeout for scripts |
Network is unreachable |
No route to destination subnet | Check ip route; fix gateway or VPN |
| Wildly varying RTT | Congestion, Wi-Fi, or CPU load on either end | Use -q over many samples; correlate with traceroute |
