Using ping command in Linux


Ping is a software utility that is used to test the network connectivity issue between two systems. This command is available for various platforms including Windows, Linux, Unix, etc.

It works by sending an ICMP echo request to a destination IP if the remote system is active it will reply with an ICMP reply message. The command is used to analyze network issues such as dropped packets or high latency.

In this article, we will discuss how to use the ping command in the Linux terminal.

How to use ping command in Linux

The syntax of using the ping command in a Linux system is given below –

ping [option] destination

Where you can find the options on the command’s manpage and the destination is the IP or hostname of a remote system.

Example of pinging a remote host

You need to use the remote host IP or hostname with the ping command for example if you want to check whether the host with IP 8.8.8.8 is up, use the following command in your terminal –

ping 8.8.8.8

This command will start pinging, to stop the process press ctrl+c

Where,

icmp_seq – represents the sequence number of each ICMP packet

ttl – The ttl means time to leave it represents the amount of time or hops a packet can take before a router discard it

time – This is the time a packet takes to reach the destination and come back to the source by default it is given in milliseconds

The example of using the hostname instead of IP address is given below-

ping google.com

In this case, the ping command first resolves the domain name to the IP address and then start sending ICMP packets to the destination IP.

How to specify the number of ping requests

You can specify the number of ICMP requests by using the option -c with the ping command. Use the following command to stop pinging after sending 10 packets –

ping -c 10 google.com

Now see the output in the image below –

How to set the interval between sending packets

You can set the interval in seconds between sending each packet by using the option -i with the ping command. Use the following command to set the interval of 5 seconds to send the ping request –

ping -i 5 -c 10 google.com

This command will send 10 packets with a gap of 5 seconds in sending each packet.

Using option -f with ping command

You can run a flood ping by using the option -f with the ping command. It sends packets as soon as possible so used to test the performance of a network.

Now use the following command to run a flood ping –

ping -f google.com

Press ctrl+c to stop pinging, see the output of the command –

To explore more options that can be used with the ping command see its manual page by executing the given command –

man ping

Conclusion

This is how you can use the ping command in Linux. Now if you have a query then leave it in the comments below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.