Linux Commands

Ping Command Linux

The ping command in Linux is used for querying the status of web servers. If you get any response from the pinged web server, the target web server is available; otherwise, not. In this guide, we will explain to you the usage of the ping command in Linux.

How to use the Ping Command in Linux?

It is very easy to use the ping command in Linux and you will get to know this by going through the following examples:

Example # 1: Simply Pinging a Web Server

You can simply use the ping command without any options for querying the active status of a web server. In this example, we will try to ping Google’s server with the help of the command shown below:

$ ping www.google.com

Soon, after the execution of the above-mentioned command, you will start receiving the responses from the target web server (if it is alive) after regular intervals (the default value of these intervals for the ping command in Linux is 1 second) as shown in the following image:

To stop the execution of the ping command, you will have to press the “Ctrl + C” key combination.

Example # 2: Pinging a Web Server After Specified Intervals

In some situations, you might want a customized interval for receiving the responses from the pinged web server. To specify a customized interval, you can use the ping command as shown below:

$ ping –i 3 www.google.com

Now, this command will ping the specified web server after 3 seconds instead of 1 second as shown in the following image. Again, you can terminate the execution of the ping command by pressing “Ctrl + C”.

Example # 3: Pinging a Web Server for a Specified Number of Times

By now, you would have realized that the ping command keeps running until you manually stop it. However, if you only want to ping a web server for a certain number of times and want the ping command to terminate automatically after that threshold value is met, you can use the command shown below:

$ ping –c 3 www.google.com

This command will ping the specified server only for 3 times after which it will display the statistics report on the terminal. Then, the command will automatically terminate as shown in the following image:

Bonus Point

With the help of the above-mentioned examples, you would have understood how the ping command works in Linux. However, if you want to know more about its working, then you can learn it by running the command shown below:

$ ping --help

This command will display the help manual of the ping command on your terminal from where you will learn all of its options as shown in the following image:

Conclusion

In this article, we enlightened you about the usage of the ping command in Linux. With the help of three extremely simple yet useful examples, we elaborated on the usage of this command. Now, after reading this guide, you will be able to explore all other options that are available with this command in Linux.

Similar Posts