MOST USEFUL LINUX PING COMMAND (PING UTILITY) WITH EXAMPLES
Introduction
In this article we are going to learn How to use Linux ping command also known as ping utility.
PING is stands for Packet Internet Network Groper is a network related tool used to check network connectivity between two systems with the help of IP Address or Hostname, for example between two servers or two clients or between any two devices which are in network. To do so ping uses ICMP (Internet Control Message Protocol) to transfer and receive the packets between two devices. In simple words ping command is used as a Networking Troubleshooter. ping command was invented by Sir Mike Muuss on year 1983.
Follow below article for Linux ping command (ping Utility) with Examples :
Syntax to use Linux ping command is :
ping [OPTIONS] [Hostname/IP Address]
To check network connectivity between of any system or networking device (Router, Server..etc…) we can use ping command. Here I checking the connectivity of one of my desktop system whose IP Address is 192.168.1.103 and as shown on output below I have positive connectivity.
[root@localhost ~]# ping 192.168.0.103 # To check connectivity of any system/networking device
PING 192.168.0.103 (192.168.0.103) 56(84) bytes of data.
64 bytes from 192.168.0.103: icmp_seq=1 ttl=64 time=0.100 ms
64 bytes from 192.168.0.103: icmp_seq=2 ttl=64 time=0.065 ms
64 bytes from 192.168.0.103: icmp_seq=3 ttl=64 time=0.057 ms
64 bytes from 192.168.0.103: icmp_seq=4 ttl=64 time=0.049 ms
64 bytes from 192.168.0.103: icmp_seq=5 ttl=64 time=0.051 ms
--- 192.168.0.103 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4030ms
rtt min/avg/max/mdev = 0.049/0.064/0.100/0.020 ms
To ping to Localhost or Your own system refer the below ping command.
[root@localhost ~]# ping localhost # To ping your Own System
PING localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.043 ms
64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.041 ms
--- localhost ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3880ms
rtt min/avg/max/mdev = 0.034/0.039/0.043/0.003 ms
You can check connectivity with any domain name or website by using ping command (ping utility). Here I am checking connectivity with my own website i.e. elinuxbook.com.
[root@localhost ~]# ping elinuxbook.com # Check Connectivity with Domain Name/Website
PING elinuxbook.com (111.118.215.222) 56(84) bytes of data.
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=3.79 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=3.58 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=4.89 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=4 ttl=58 time=3.65 ms
--- elinuxbook.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3496ms
rtt min/avg/max/mdev = 3.589/3.983/4.895/0.531 ms
Also Read :
- BEST LINUX DU COMMAND WITH EXAMPLES
- USEFUL LINUX FDISK COMMAND WITH EXAMPLES – A LINUX DISK PARTITION TOOL
- MANAGING USERS AND GROUPS IN LINUX – A COMPLETE GUIDE FOR BEGINNERS
You can control the Packets of ping command and can mention how many Packets you want to send to Destination domain name or system by using ping command with atgument -c. c is referred as Count. Here I am sending 3 packets to domain elinuxbook.com. and after sending the mentioned number of packets the command will stop automatically.
[root@localhost ~]# ping -c 3 elinuxbook.com # To control Packets of ping command (ping utility )
PING elinuxbook.com (111.118.215.222) 56(84) bytes of data.
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=3.58 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=3.66 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=3.91 ms
--- elinuxbook.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2008ms
rtt min/avg/max/mdev = 3.586/3.720/3.916/0.157 ms
ping command with -i will keep Interval between two packets. i is referred as Interval. For example here I am Pinging to elinuxbook.com and set 2 seconds of Interval between two packets. That means ping will send first packet and wait for 2 seconds and then send the second packet like that the process will go on.
[root@localhost ~]# ping -i 2 elinuxbook.com # To keep interval between two packets
PING elinuxbook.com (111.118.215.222) 56(84) bytes of data.
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=3.73 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=6.06 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=3.64 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=4 ttl=58 time=3.54 ms
--- elinuxbook.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 6649ms
rtt min/avg/max/mdev = 3.544/4.246/6.062/1.050 ms
Let’s take a Task to make your concept more clear : Here I am pinging to domain elinuxbook.com and allowing Linux ping command to send 4 Packets with 3 Seconds of Interval between two Packets. Refer the command below.
[root@localhost ~]# ping -c 4 -i 3 elinuxbook.com PING elinuxbook.com (111.118.215.222) 56(84) bytes of data. 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=3.74 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=3.44 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=3.50 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=4 ttl=58 time=6.28 ms --- elinuxbook.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 9016ms rtt min/avg/max/mdev = 3.448/4.245/6.282/1.181 ms
Normally the Packet Size of Linux ping command (ping utility) is 56 Bytes or 64 Bytes (Highlighted in Red color). But you can set your own Packet size by using ping command with argument -s.
[root@localhost ~]# ping elinuxbook.com PING elinuxbook.com (111.118.215.222) 56(84) bytes of data. 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=3.97 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=7.68 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=4.60 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=4 ttl=58 time=4.80 ms 64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=5 ttl=58 time=19.4 ms ^C --- elinuxbook.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4386ms rtt min/avg/max/mdev = 3.970/8.094/19.412/5.801 ms # Refer the below command to Set your Packet Size : [root@localhost ~]# ping -s 70 elinuxbook.com # To Set Packet Size PING elinuxbook.com (111.118.215.222) 70(98) bytes of data. 78 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=5.21 ms 78 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=7.02 ms 78 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=3.94 ms 78 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=4 ttl=58 time=8.94 ms 78 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=5 ttl=58 time=4.39 ms ^C --- elinuxbook.com ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4740ms rtt min/avg/max/mdev = 3.947/5.905/8.942/1.849 ms
Linux ping command with -f will send the rapid packet requests to destination hosts i.e Hundred time more faster then normal ping. In this kind of pinging you will not able to see any output. Ping command will show you the direct result when you stop the pinging. You can stop the pinging by using Keyboard Key i.e. CTRL+C. f is referred as Flood. Here you can see on sample output below ping sends 1848 No’s of Packets within 7807 Mili Seconds.
[root@localhost ~]# ping -f elinuxbook.com # For Rapid Packet Transfer PING elinuxbook.com (111.118.215.222) 56(84) bytes of data. .^C --- elinuxbook.com ping statistics --- 1848 packets transmitted, 1847 received, 0% packet loss, time 7807ms rtt min/avg/max/mdev = 3.360/3.925/13.754/0.679 ms, pipe 2, ipg/ewma 4.227/3.762 ms
You are using ping command with argument -w means you have set a deadline/timeout for ping command to stop the packet sending automatically. Here I have set a 3 Seconds as a deadline, that means the pinging will stop automatically after 3 Seconds.
[root@localhost ~]# ping -w 3 elinuxbook.com # Set Deadline for ping command
PING elinuxbook.com (111.118.215.222) 56(84) bytes of data.
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=1 ttl=58 time=4.04 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=2 ttl=58 time=4.12 ms
64 bytes from cp-in-9.webhostbox.net (111.118.215.222): icmp_seq=3 ttl=58 time=4.13 ms
--- elinuxbook.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3002ms
rtt min/avg/max/mdev = 4.048/4.105/4.139/0.040 ms
ping command with -q is for Silent Pinging or Quiet Pinging. It will show you the Result of the pinging when you stop it using CTRL+C.
[root@localhost ~]# ping -q elinuxbook.com # For Silent or Quiet Pinging
PING elinuxbook.com (111.118.215.222) 56(84) bytes of data.
^C
--- elinuxbook.com ping statistics ---
14 packets transmitted, 14 received, 0% packet loss, time 13428ms
rtt min/avg/max/mdev = 3.936/4.891/8.402/1.253 ms
you can use Linux ping command with -n for Only Numerical Output.
[root@localhost ~]# ping -n elinuxbook.com PING elinuxbook.com (111.118.215.222) 56(84) bytes of data. 64 bytes from 111.118.215.222: icmp_seq=1 ttl=58 time=8.51 ms 64 bytes from 111.118.215.222: icmp_seq=2 ttl=58 time=12.3 ms 64 bytes from 111.118.215.222: icmp_seq=3 ttl=58 time=19.1 ms 64 bytes from 111.118.215.222: icmp_seq=4 ttl=58 time=4.78 ms 64 bytes from 111.118.215.222: icmp_seq=5 ttl=58 time=5.78 ms 64 bytes from 111.118.215.222: icmp_seq=6 ttl=58 time=7.09 ms ^C --- elinuxbook.com ping statistics --- 6 packets transmitted, 6 received, 0% packet loss, time 5103ms rtt min/avg/max/mdev = 4.789/9.608/19.114/4.886 ms
To check installed Linux ping command Package version we can use ping command with argument -V.
[root@localhost ~]# ping -V # To check Installed ping command Package Version
ping utility, iputils-sss20071127
For more Linux ping command related arguments and options refer the below command.
[root@localhost ~]# ping -help # For more Linux ping command Related Options
Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]
[-p pattern] [-s packetsize] [-t ttl] [-I interface or address]
[-M mtu discovery hint] [-S sndbuf]
[ -T timestamp option ] [ -Q tos ] [hop1 ...] destination
You can refer man page of ping command for deep information related commands and theory.
[root@localhost ~]# man ping # To Refer man page/help page of ping
We tried to include as much Linux ping Command (ping utility) with Examples. If something missed out then please comment on comment box below so that we can include in the article.
If you found this article useful then Like Us, Share Us, Subscribe our Newsletter OR if you have something to say then feel free to comment on the comment box below.