The ping (Packet INternet Groper) command is one of the most widely used utility across different Operating systems: from Windows to Linux.
It’s a network troubleshooting tool used for testing reachability of remote systems, servers, and network devices.
It achieves this by sending an ICMP echo request to a remote system. The ICMP packet requests are received and relayed back to the source indicating that the host is up.
In this guide, we will look at how it is used and the various options that can be passed to achieve different results.
Table of Contents
- 1 Linux ping Command Syntax
- 2 Using the ping command to get the IP address of a host
- 3 Using the ping command to test connectivity or reachability of a system
- 4 Specify time interval between ping requests
- 5 Modify the ping packet size
- 6 Specify number of time to send the ping packet size
- 7 Flood a target system
- 8 Print timestamp of ping requests
- 9 Conclusion
Linux ping Command Syntax
The syntax of the Linux ping command is quite simple and straight forward.
ping [option] [hostname or IP address]
Using the ping command to get the IP address of a host
We can use the ping command to find out the IP address of a website. The ping command output prints the IP address of the host.
$ ping journaldev.com PING journaldev.com (18.104.22.168): 56 data bytes 64 bytes from 22.214.171.124: icmp_seq=0 ttl=56 time=59.133 ms 64 bytes from 126.96.36.199: icmp_seq=1 ttl=56 time=43.917 ms
Using the ping command to test connectivity or reachability of a system
The most basic usage of ping command involves sending a ping request to a website address or hostname as shown.
Alternatively, you can ping a server by specifying its IP address as shown.
It’s important to note that in the above examples, the ping command will continue sending ping requests until you press CRTL + C.
Ping command uses DNS resolver to find out the IP address of the host and then sends the ping request. If the hostname is invalid, it will return “Unknown host” error.
$ ping google ping: cannot resolve google: Unknown host $ ping sasadsasdd.com ping: cannot resolve sasadsasdd.com: Unknown host $
Specify time interval between ping requests
There’s a 1-second gap between ping requests by default. If you want to modify this and specify a higher value, use the
-i argument followed by the time interval as shown.
ping -i 3 google.com
In the example above the time interval between ping packets is 3 seconds.
Modify the ping packet size
The number of bytes contained in a ping request is 56 by default ( 64 bytes if you include the ping header). You can, however, alter this value to your preference by using the
-s option followed by the value. To change the value to 80, execute the command.
ping -s 80 google.com
Specify number of time to send the ping packet size
As you have observed in previous examples, you need to hit CTRL + C to interrupt the sending of ping packets. To avoid this inconvenience, you can specify the number of packets to be sent using the
-c flag. For instance, to send 5 ping packets, run the below command.
ping -c 5 google.com
The above command sends 5 ping packets to the target and finally stops.
Flood a target system
Yes, You are probably skeptical about this, but ping command can also be used to flood a target. You can achieve this using the
ping -f jaykiarie.com
DISCLAIMER: Caution should be taken as flooding a target system with ping requests can lead to a DOS attack which can degrade a system’s reachability or connectivity.
Print timestamp of ping requests
If you wish, you can print the timestamp during which the ping packets are sent. This is achieved using the
-D option. The timestamp is a combination of Unix time and microseconds.
As we have seen, ping is a very useful command for network troubleshooting and helps System administrators and regular users to diagnose network problems involving connectivity between systems. You can run “man ping” command to check out all the options ping command provides.