Beginners Guide for Ping Command in Linux

Linux TLDR
Last Updated:
Reading time: 4 minutes

PING, also known as β€œPacket Internet Groper”, is the most common networking tool used in Windows, Linux, and macOS to test the connection between the source and the destination.

The destination, or remote system, could be a web server, your router, or a computer on your local network; you will specify them with their domain or IP address.

When you specify the destination (domain or IP address), the ping command will send a series of ICMP (Internet Control Message Protocol) packets to the remote system and wait for the response.

In the response output, you will get different pieces of information using which you can determine whether the remote system is alive or not, the latency of the network, and how many packets are dropped.

Although you might already be aware of the basic usage of this command, stick with this article to learn several variations and options for the ping command (with examples).

Tutorial Details

Difficulty LevelLow
Root or Sudo PrivilegesNo
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Internet RequiredNo

Ping Command Usage

The simplest way to use the ping command (which you might already know) is to specify the domain or IP address of the destination without any options.

In the following command, β€œ” is being ping to test whether the domain is alive or not by sending ICMP packets of 56 bytes.

$ ping


$ ping


Pinging the remote host

Note that the ping command will keep pinging the remote system unless you manually stop it by pressing the β€œCtrl+C” shortcut key.

Once you stop the ping command, it will give you a summary of all the transmissions made between the source and destination that includes the following information:

  • from: It identifies the target by its IP address (the simplest way to obtain the IP address of any domain name).
  • icmp_seq: It’s the sequence of the ICMP packet sent to the server in order.
  • ttl: It tells how long a packet is allowed to stay in a network before it is thrown away by a router.
  • time: It tells the amount of time it took for the referenced packet to reach the remote system and come back to the origin.

In addition, you will receive a summary of the total number of transmitted and received packets, the number of lost packets, and the average time spent exchanging a packet.

Now that you know how the ping command works and how to read its output, let’s see some of the other examples of the ping command’s usage with its options.

Ping a Host Only a Specific Number of Times

The default behavior of the ping command is to keep pinging the remote system unless the user manually stops the ping command.

However, you can use the β€œ-c” flag with the number of packets to send on the remote system, after which the ping command will automatically stop.

For example, the following command will only ping β€œ” twice.

$ ping -c 2


Sending a definite number of packets to the remote system

Apart from the number of packets, you can stop the ping command by specifying the timeout that you will learn in the next section.

Setting the Ping Timeout

Aside from defining the number of packets to send, you can also specify the timeout using the β€œ-w” flag, at which the ping command will automatically stop.

For example, the following command will only ping β€œ” for five seconds.

$ ping -w 5


Setting the timeout for the ping command

Change the Time Interval While Sending Each Packet

The default behavior of the ping command is to send packets at an interval of one second. However, you can use the β€œ-i” flag to change the time interval between two pings to prevent getting blocked by the remote system.

For example, the following command will send ICMP packets to the remote system after two seconds on each request.

$ ping -i 2


Sending packet to remote system after two seconds

It should be noted that you can specify the time interval in milliseconds by assigning a value in floating point (decimal value), but you must do so as root or with sudo privileges.

Reducing the interval time below one second will increase the chance of packet loss (especially in a slow network).

For example, the following command will send the ICMP packet to the remote system after 0.5 seconds (500 ms).

$ ping -i 0.5


Sending packet to remote system after point five milliseconds

Changing the ICMP Packet Size

By default, the ping command sends the ICMP packets in 56 bytes, as you can see in the earlier outputs, but you are not limited to using this predefined size. Using the β€œ-s” flag, you can send a remote system a custom-sized ICMP packet in bytes.

The following command will send an ICMP packet size of 100 bytes to β€œgoogle.comβ€œ.

$ ping -s 100


Using custom packet size while sending on remote system

Do not Lookup the Symbolic Names for the Host

By default, the ping command looks for the symbolic names in specified DNS records to give the host name instead of an IP address. This could be easily avoided by using the β€œ-n” flag.

For example, the following command will only give you the numeric output for β€œ” instead of symbolic names.

$ ping -n


Do not look for the symbolic names

DoS Attack with Ping Flooding

One of the simple ways to determine the response of your remote system (or server) under high-load conditions is by initiating the DoS attack using the ping command, also known as β€œping floodingβ€œ.

In this scenario, the ping command will send a large number of ping requests as fast as possible in a very short time frame.

If you are ping flooding on your own server, then it’s okay (unless you are using shared hosting), but if you are testing on someone else’s server, you might get no response or get blocked by the server as many servers do not allow ICMP requests.

For example, the following command with the β€œ-f” flag will stress test β€œ” unless you manually interrupt the ping command.

The following command will only be initiated by root or users with sudo privileges.
$ ping -f


Ping overload on the remote system

When you initiate the ping flood, you will see some dots keep appearing and disappearing in the output.

Every β€œ.” dot is a request, and a backspace is the answer. Since the backspace clears the dots, the dot appears and disappears.

Every Successful Ping is Accompanied by a Sound Alert.

If you use the β€œ-a” flag with the ping command, every successful ping request to the remote system will make a sound.

Some systems might not hear the beep noise. If it happens to you, notify us of your system name in the comment section.
$ ping -a


Alert with sound on every successful ping

So, that’s all for now.

If you have any questions or queries related to this topic, feel free to ask them in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.