Ping Command In Linux with Examples

The ping command is provided by the Linux distributions like Ubuntu, Debian, Mint, Kali, CentOS, RHEL, SUSE by default. The term ping is the short form of the “Packet Internet Groper”. The ping command is used to check remote system network connectivity and troubleshoot the problem. The ping command uses the ICMP protocol and packets for communication with the remote or target host. It creates ICMP packets and sends them to the target and shows results according to the responses of the target. The ping command is not provided as a sole package The ping command is provided with the package named iputils.

ping Command Help

Even the ping is a simple process the ping command provides different parameters in order to set different features of the ping command. These parameters and help information can be listed with the -h option like below.

$ ping -h

The output will be like below.

ping Command Help

ping Command Syntax

The ping command has very simple syntax where the option and target are specified like below.

ping OPTIONS TARGET
  • The OPTIONS is used to set some parameters for the ping command. This is optional and single or more options can be specified at the same time.
  • The TARGET is the remote system we want to ping. The TARGET can be and IP address in IPv4 or IPv6 or a hostname like linuxtect.com . TARGET is required.

ping Target

The most popular and simplest usage is pinging the remote or target system. The target system can be provided with its IP address or domain name. In the following example, we will specify the domain name.

$ ping linuxtect.com

The output of the ping command will be like below. The ping command output contains the following information.

  • 64 bytes is the size of the ICMP payload.
  • icmp_seq is the sequence number of the ICMP package for this ping operation.
  • ttl is the time to live parameter for the ping result.
  • time is the time to reach to the target.
Linux ping Domain Name

We can also ping an IP address like below.

$ ping 104.26.2.137

The Linux ping command will continuously ping which is different from the Windows ping command. So the Linux ping command will run forever unless we cancel or stop it. The CTRL+c keys can be used to stop the Linux ping command.

CTRL+C To Stop Ping

At the end of the ping there will be some statistics about ping packets.

  • 30 packets transmitted show how many ICMP or ping packets sent to target.
  • 30 received shows how many responses received for the request.
  • 0% packet loss is the percentage of lost packets or unreplied ICMP or ping packets.
  • time 29045ms is total time from start of the ping packet to the end.
  • min is the minimum round trip time from sending ICMP packet to get response.
  • avg is the average round trip time from sending ICMP packet to get response.
  • max is the maximum round trip time from sending ICMP packet to get response.

Specify Number of Ping Packets

By default Linux, ping command sends an unlimited number of ping packets running forever. But alternatively, we can specify the number of the ping packets. The -c option and the number of the packets we want to send. In the following example, we will send only 3 packets to the remote system. With this option, there is no need to abort the ping command because it will stop after the packet count limit is reached.

$ ping -c 3 linuxtect.com

The output will be like below.

PING linuxtect.com (104.26.2.137) 56(84) bytes of data.
64 bytes from 104.26.2.137 (104.26.2.137): icmp_seq=1 ttl=128 time=38.1 ms
64 bytes from 104.26.2.137 (104.26.2.137): icmp_seq=2 ttl=128 time=38.0 ms
64 bytes from 104.26.2.137 (104.26.2.137): icmp_seq=3 ttl=128 time=38.3 ms
--- linuxtect.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 38.030/38.148/38.324/0.126 ms

Specify Ping Interval

Ping packets are sent in a sequential way with a time interval of 1 second. Every 1 second, a single ICMP packet will be sent to the target. We can change this ping interval by using the -i option and providing the interval value in seconds. In the following example, we will set the ping interval as 3 seconds.

$ ping -i 3 linuxtect.com

The time intervals can be also set as milliseconds by providing a floating-point.

$ ping -i 3.5 linuxtect.com

Specify Ping Packet Size

By default, the ping packet or ICMP packet contains a payload of 64 bytes. This packet or payload size can be changed with the -s option by providing the size in bytes. The payload data will be random data like sequential letters or numbers etc. In the following example, we will set the ping size as 128 bytes.

$ ping -s 128 linuxtect.com

Specify Ping Timeout

By default when a ping packet is sent to the target after 2 seconds the sender will stop waiting for a response and print this packet as unreachable. The timeout for the ping command can be specified with the -w option and provide the number of the timeout seconds.

$ ping -w 3 linuxtect.com

Show Only Ping Result Summary

By default, the ping command will show every packet sent to the target and its status and response line by line to the command-line interface. If you only need the general statistics about the ping command and prevent every packet status you can use the -q option. The -q is quite short form.

$ ping -q -c 5 linuxtect.com
Show Only Ping Result Summary

Ping Flood

By default, the ping command will send ICMP packets sequentially with a 1-second interval. This means every 1 second single ICMP packet will send to the target. The flood mode will change this behavior and send ICMP packets as much as the system can be and flood a lot of ICMP packets to the target. The -f option is used to flood ping packets.

$ ping -f linuxtect.com

Specify TTL (Time To Live) For Ping

TTL (Time To Live) is used to specify how many hops the packet can be routed. In every hop, the ICMP packet TTL is decreased 1 and when the TTL reaches 0 the packet is dropped. By default, Linux systems set TTL for packets as 128 but by using the -t option and the TTL count it can be changed easily. In the following example, we will set the TTL count as 32 for the ping command.

$ ping -t 32 linuxtect.com

Ping IPv6 IP Address

By default ping command use the IPv4 which is the most popular IP protocol version. But we can also use the ping command for IPv6 addresses. The -6 option is used to specify the IPv6.

$ ping -6 linuxtect.com

Audible Ping

The ping command provides very interesting features where when the ping is successful we can play sound or audio which is called an audible ping.

$ ping -a linuxtect.com

Print ping Command Version

The ping command is provided with the iputils package. The ping command version can be displayed with the -V option.

$ ping -V google.com
ping from iputils s20200821

Leave a Comment