Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Networking

Linux ping command

Reference for the Linux ping command: send ICMP echo requests, limit counts and timeouts, read packet loss and round-trip times, and use ping in scripts.

ping sends ICMP echo request packets to a host and waits for echo replies. Each reply tells you the host is reachable, how long the round trip took, and the TTL left in the packet. At the end, ping prints a summary with packet loss and minimum, average, maximum and deviation of the round-trip time.

It is the first tool to reach for when "the network is down", but a missing reply is not proof of a failure: many hosts and firewalls drop ICMP on purpose.

Terminal
ping -c 4 example.com
ping -c 1 -W 2 192.0.2.10

Try it

ping needs raw sockets and a network, neither available in our sandbox, so the real command is read-only below. The runnable part shows how scripts read its summary line, using a saved sample.

Read-only: typical output.

CONSOLE
$ ping -c 3 example.com
PING example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.2 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=10.8 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=11.0 ms

--- example.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 10.8/11.0/11.2/0.163 ms
Bash Parse a ping summary in a script

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
ping [OPTION]... DESTINATION
Option Description
-c COUNT Stop after COUNT replies. Without it, Linux ping runs until Ctrl+C.
-W SECONDS How long to wait for each reply.
-w SECONDS Overall deadline for the whole run.
-i SECONDS Interval between packets (default 1; values under 0.2 need root).
-s BYTES Payload size (default 56, giving 64 bytes with the ICMP header).
-t TTL Set the time-to-live of outgoing packets.
-4, -6 Force IPv4 or IPv6.
-q Quiet: only the summary.
-D Print a timestamp before each line.
-I IFACE Send from an interface or source address.
-M do Forbid fragmentation; useful for finding the path MTU with -s.

Returns: 0 if at least one reply arrived, 1 if none did, 2 for other errors such as an unresolvable name.

Usage notes

  • No reply does not mean down. Cloud providers and firewalls often filter ICMP. Test the real service port with nc or curl as well.
  • Name versus address. If ping 8.8.8.8 works but ping example.com fails, the network is fine and DNS is the problem; check with dig.
  • Reading the numbers: a high mdev means unstable latency; steady loss on every Nth packet hints at rate limiting; the TTL (64, 128, 255 at the start) lets you guess how many hops are between you and the host.
  • Always use -c in scripts, otherwise the command never ends. Combine with -W so a dead host does not stall you.
  • Path MTU: ping -M do -s 1472 HOST succeeds only if a 1500-byte packet fits; lower -s until it does.
  • Permissions: modern kernels let normal users send ICMP echo through unprivileged sockets; on some systems ping is setuid or has capabilities. In containers it may fail with "Operation not permitted".
  • IPv6: use ping -6 or ping6 on older systems; link-local addresses need the interface, such as fe80::1%eth0.
  • For routes rather than a single hop count, use traceroute.