Ping Command in Linux

The ping command is one of the most used tools for troubleshooting, testing, and diagnosing network connectivity issues.
Ping works by sending one or more ICMP (Internet Control Message Protocol) Echo Request packets to a specified destination IP on the network and waiting for a reply. When the destination receives the packet, it responds with an ICMP echo reply.
With the ping command, you can determine whether a remote destination IP is active or inactive. You can also find the round-trip delay in communicating with the destination and check whether there is a packet loss.
ping is part of the iputils (or iputils-ping) package, which is pre-installed on nearly all Linux distributions. It is also available on Windows, macOS, and FreeBSD.
How to Use the Ping Command
The syntax for the ping command is as follows:
ping [OPTIONS] DESTINATIONTo better illustrate how the ping command works, we will ping google.com:
ping google.comThe output will look something like this:
PING google.com (172.217.22.206) 56(84) bytes of data.
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=1 ttl=53 time=40.2 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=2 ttl=53 time=41.8 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=3 ttl=53 time=47.4 ms
64 bytes from muc11s01-in-f14.1e100.net (172.217.22.206): icmp_seq=4 ttl=53 time=41.4 ms
^C
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 40.163/42.700/47.408/2.790 msThe ping command resolves the domain name into an IP address and starts sending ICMP packets to the destination IP. If the destination IP is reachable, it will respond and the ping command prints a line that includes the following fields:
- The number of data bytes. The default is 56, which translates into 64 ICMP data bytes -
64 bytes. - The IP address of the destination -
from muc11s01-in-f14.1e100.net (172.217.22.206). - The ICMP sequence number for each packet.
icmp_seq=1. - The Time to Live -
ttl=53- How does TTL work? . - The ping time, measured in milliseconds, which is the round trip time for the packet to reach the host and the response to return to the sender. -
time=41.4 ms.
By default, the interval between sending a new packet is one second.
The ping command will continue to send ICMP packets to the destination IP address until it receives an interrupt. To stop the command, just hit the Ctrl+C key combination.
Once the command stops, it displays statistics, including the percentage of packet loss. Packet loss means the data was dropped somewhere in the network, indicating an issue within the network. If there is a packet loss, you can use the traceroute
command to identify where the packet loss occurs. For packet-level capture, use tcpdump
.
If ping does not return a reply, it means that the network communication is not established. When this happens, it does not always mean that the destination IP is not active. Some hosts may have a firewall that is blocking the ICMP traffic or set to not respond to ping requests.
On success, the ping command exits with code 0. Otherwise, it will exit with code 1 or 2. This can be useful when using the ping utility in a shell script.
In the following sections, we will go over the most commonly used ping command options.
ping requires elevated permissions. If you see a permission error, run it with sudo or install ping with the right capabilities.Specify the Number of Packets
As already mentioned, by default, ping will continue to send ICMP packets until it receives an interrupt signal. To specify the number of Echo Request packets to be sent after which ping will exit, use the -c option followed by the number of the packets:
ping -c 1 DESTINATIONFor example, to ping linuxize.com only one time you would use:
ping -c 1 linuxize.comSpecify the Source Interface
The default behavior of the ping command is to send ICMP packets via the default route. If you have multiple interfaces on your machine you can specify the source interface with the -I option:
ping -I INTERFACE_NAME DESTINATIONThe following command will ping linuxize.com using em2 as a source interface:
ping -I em2 linuxize.comSpecify the Internet Protocol
When you run the ping command, it will use either IPv4 or IPv6, depending on your machine DNS settings.
To force ping to use IPv4, pass the -4 option, or use its alias ping4:
ping -4 DESTINATIONFor IPv6, pass the -6 option or use ping6:
ping -6 DESTINATIONChange the Interval and Timeout
By default, ping sends one packet per second. You can control three separate time values: the interval between packets, the per-reply timeout, and an overall deadline.
Use -i to change how often packets are sent. The following command sends one packet every two seconds:
ping -i 2 google.comValues below 0.2 require root privileges. Setting a longer interval is useful for light background monitoring; setting a shorter one lets you gather more samples quickly.
Use -W to set how long ping waits for a response when replies are not coming back. The following command gives ping a two-second response window:
ping -W 2 google.comThe default wait time is 10 seconds. Reducing it is useful on known-fast links where a slow reply indicates a real problem.
Use -w to set an overall deadline in seconds, after which ping stops regardless of how many packets were sent:
ping -w 10 google.comThis is particularly useful in shell scripts where you want to bound the total run time regardless of packet count.
Change the Packet Size
To change the size of the ICMP payload, use the -s option:
ping -s 120 DESTINATIONQuiet Output
To show only a summary, use the -q option:
ping -q -c 5 DESTINATIONQuick Reference
| Option | Description |
|---|---|
-c COUNT | Send COUNT packets then exit |
-i INTERVAL | Seconds between packets (default: 1) |
-W TIMEOUT | Seconds to wait for a response when no replies are received |
-w DEADLINE | Stop after DEADLINE seconds total |
-s SIZE | ICMP payload size in bytes (default: 56) |
-q | Quiet output (summary only) |
-I INTERFACE | Send via INTERFACE |
-4 | Force IPv4 |
-6 | Force IPv6 |
Conclusion
ping is a straightforward but powerful tool for testing IP-level connectivity, measuring latency, and spotting packet loss. For a deeper look at all available options, run man ping in your terminal.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page