AMP AMP

ping Command in Linux with Examples

Ping Command

Ping command is the simple way to send and receive data to another computer over the network. It is most frequently used to test, whether the system is reachable through network. It is used to check how much time it takes to transfer and receive the data.

Basic Syntax

ping < options> hostname < packetsize> < count>

Pinging the host

Ping command is used to check whether the host is alive or not. It sends and receives the packets in 1 sec time interval.

[user1@linuxhelp ~]$ ping google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=10.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=13.3 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=3 ttl=57 time=12.1 ms
--- google.com ping statistics ---
3 packets transmitted, 5 received, 0% packet loss, time 2345ms
rtt min/avg/max/mdev = 17.876/38.210/74.353/25.625 ms

Here, it keeps on pinging unless it is destructed manually. And at last it will show up the packets loss and transferred.

Increase or decrease Time interval

The ping time interval can be increased or decreased so that it will be allowed to wait for specified time to send the next packets.

-i is the option to increase and decrease the time interval.
Increase time interval
Increase in time interval will wait for 5 seconds to send the next packets.

[user1@linuxhelp ~]$ ping -i 5 google.com  
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=10.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=13.3 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=3 ttl=57 time=12.1 ms
--- google.com ping statistics ---
3 packets transmitted, 5 received, 0% packet loss, time 2345ms
rtt min/avg/max/mdev = 17.876/38.210/74.353/25.625 ms

Decrease in time interval

Decrease in time interval will reduce the time interval to send the next packets.

[user1@linuxhelp ~]$ ping -i 0.9 google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=6.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=4.3 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=3 ttl=57 time=4.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=4 ttl=57 time=5.6 ms
--- google.com ping statistics ---
4 packets transmitted, 5 received, 0% packet loss, time 2345ms
rtt min/avg/max/mdev = 17.876/38.210/74.353/25.625 ms


Only super user can notify the time interval for below 0.1 seconds, if others try then the following message will be displayed.

[user1@linuxhelp ~]$ ping -i 0.1 google.com  
PING google.com (216.58.197.46) 56(84) bytes of data.
ping: cannot flood  minimal interval, allowed for user, is 200ms

Sending, receiving and stopping packets at minimum count

-c is the option to send, receive and stop the packets at the minimum count.

The below command runs for 4 counts and cuts automatically and exits.

[user1@linuxhelp ~]$ ping -c 4 google.com  
PING google.com (216.58.196.110) 56(84) bytes of data.
64 bytes from maa03s19-in-f110.1e100.net (216.58.196.110): icmp_seq=1 ttl=57 time=28.9 ms
64 bytes from maa03s19-in-f110.1e100.net (216.58.196.110): icmp_seq=2 ttl=57 time=79.5 ms
64 bytes from maa03s19-in-f110.1e100.net (216.58.196.110): icmp_seq=3 ttl=57 time=12.0 ms
64 bytes from maa03s19-in-f110.1e100.net (216.58.196.110): icmp_seq=4 ttl=57 time=22.0 ms--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3026ms
rtt min/avg/max/mdev = 12.030/35.628/79.557/26.063 ms

Flood the network

Super users can send hundreds of packets per second. It prints ' .' when a packet is sent and prints ‘ ^’ when a packet is received.

-f is the option used for flooding network.
Ping command cannot be used by the normal user.

[root@linuxhelp user1]# ping -f google.com 
PING linuxhelp (127.0.0.1) 56(84) bytes of data.
.&hellip ^
--- linuxhelp ping statistics ---
4241289 packets transmitted, 4241289 received, 0% packet loss, time 49006ms
rtt min/avg/max/mdev = 0.004/0.004/0.045/0.002 ms, ipg/ewma 0.011/0.005 ms

It transfers lot of packets and receives the same amount. It should be done only with super user.

Ping summary statistics

Ping summary statistics prints the details of packets sent and received.

-q is the option used to view the statistics.

[user1@linuxhelp ~]$ ping -c 5 -q google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.

--- google.com ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4074ms
rtt min/avg/max/mdev = 14.796/44.831/68.701/22.146 ms

Change ping packet size

Generally, the packets are sent and received in default value of 64 bytes.

-s is option used to change the packet size.


Ping command changes the packet size from 64 to 72 bytes. It is displayed 72 because it calculates the packet lost, received and transmitted.

[user1@linuxhelp ~]$ ping -s 100 google.com 
PING linuxhelp (127.0.0.1) 100(128) bytes of data.
72 bytes from linuxhelp (127.0.0.1): icmp_seq=1 ttl=64 time=0.031 ms
72 bytes from linuxhelp (127.0.0.1): icmp_seq=2 ttl=64 time=0.044 ms
72 bytes from linuxhelp (127.0.0.1): icmp_seq=3 ttl=64 time=0.045 ms
--- linuxhelp ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2278ms
rtt min/avg/max/mdev = 0.031/0.040/0.045/0.006 ms

Timed pinging

Ping command is used to ping for specified time period and it exits automatically irrespective of the packets sent or received.

-w is option the command for timed pinging.

[user1@linuxhelp ~]$ ping -w 5 google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=10.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=13.3 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=3 ttl=57 time=12.1 ms
--- google.com ping statistics ---
3 packets transmitted, 5 received, 0% packet loss, time 2345ms
rtt min/avg/max/mdev = 17.876/38.210/74.353/25.625 ms

It will ping for ' 5' seconds and exits automatically.

Ping in specified path

Ping command can be used in specific path. Here, it will sent the packets through this path and received, if there is any destructed in these path then it returns failure ping.

[user1@linuxhelp ~]$ ping hostname1 hostname2 hostname3

Audible ping

It simply gives a beep sound when the desired host is reachable.

-a is the option for audible ping.

[user1@linuxhelp ~]$ ping -a google.com 
PING google.com (216.58.197.78) 56(84) bytes of data.
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=1 ttl=57 time=10.1 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=2 ttl=57 time=13.3 ms
64 bytes from maa03s21-in-f14.1e100.net (216.58.197.78): icmp_seq=3 ttl=57 time=12.1 ms
--- google.com ping statistics ---
3 packets transmitted, 5 received, 0% packet loss, time 2345ms
rtt min/avg/max/mdev = 17.876/38.210/74.353/25.625 ms


It will work only in terminal number 1 to 7 as well as gnome terminal not in console window.

Tag : ping command
FAQ
Q
How to use flood execution of ping command?
A
For every ECHO_REQUEST sent a period ``.'' is printed, while for ever ECHO_REPLY received a backspace is printed. This provides a rapid display of how many packets are being dropped. I
Q
How to set until the timeout expired deadline of execution for ping command?
A
You can execute the ping command With deadline option, ping waits for count ECHO_REPLY packets until the timeout expires by mention the option of "-c". For Ex: "ping -c 5 www.example.com""
Q
How to set specifies the number of data bytes to be sent to the destination host?
A
You can set earlier a default sized packets were sent to a host but we can send light and heavy packet by using "-s" option. For Ex: "ping -s 40 -c 5 www.example.com"
Q
How to set wait interval seconds between sending each packet while executing the ping command?
A
The default wait time for 1 sec to send next packet in ping command. If you want to change this time by using -i option. For Ex: "ping -i 2 www.geeksforgeeks.org".
Q
How to set continues execution of ping command on both Windows and Linux?
A
You can use the option of "-t" with ping command on both windows and Linux. For Syntax: "ping 0.0.0.0 -t".