The Linux Ping Command

Ping or Packet Internet Groper is a network management utility that can check the connection status between a source and destination computer/device over an IP network. It also helps you estimate the time it takes to send and receive a response from the network.

We all have our favorite websites that we visit frequently; if one of them doesn’t load, we really want to know why. Is it because we don’t have an Internet connection, or is it problems with our Internet service provider that are preventing us from accessing the website? Another reason could be the unavailability of the website itself. Whatever the reason, the Linux Ping command can give you all the answers.

Ping uses the Internet Control Message Protocol (ICMP) to send and receive echo messages to and from the host or target computers to keep us informed of network performance. An ICMP request message is sent to the target computer; if the target IP address is available, it sends an ICMP message response to the host computer. This informs us about the connectivity status of the network, such as the round-trip time – the time it takes to send and receive an information packet.

Using the Ping command

In the Linux terminal type the following command:


This is the output you will get:

Linux ping command

Let us describe(in alphabetic order) the commonly used options that you can see above:

Option Description
a Use this option for a beep sound when the peer is reachable
b Use this option to allow pinging a broadcast address
B Use this option if you do not want to allow the ping to change the source address of the probe
c (count) Use this option to set the number of times to send the ping request
d Use this option to set the SO-DEBUG option on the socket being used
f Use this option to flood the network by sending hundred or more packets per second
i (interval) Use this option to specify an interval between successive packet transmissions. The default value of interval is 1 second
I (interface address) Use this option to set source address to the specified interface address. This option is required when pinging IPv6 link local address. Its argument can be an IP address or name of the device.
l (preload) Use this option to set the number of packets to send without waiting for a reply. For selecting a value more than 3, you need to be a super user.
n Use this option to display network addresses as numbers rather than as hostnames
q Use this option to display a quiet output. It means that only the summary is displayed at startup and finish time
T (ttl) Use this option to set the Time To Live
v Use this option for verbose output
V Use this option to display the version and exit
w (deadline) Use this option to specify a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received.
W (timeout) Use this option to set the time(seconds) to wait for a response

Some Basic Ping functions

Here are some basic ping functions that you will be used to check the performance of your network:

Pinging the host for availability

You can check if a host is alive or not through the following ping command:

$ ping host-name/IP

Press Ctrl+C for breaking the command

Pinging the host for availability

Increase/Decrease interval between ping packets

The default time interval between sending each packet is 1 second in Linux. You can increase the time interval by setting a value greater than 1 and decrease it by setting a value less than 1.Advertisement

Here is an example to increase the time interval between two pings:

$ ping -i 5

Here is an example to decrease the time interval between two pings:

$ ping -i 0.5

As you can see in the following image, you need to be a superuser in order to set this time interval lesser than 0.2 seconds:

Increasing/Decreasing interval between ping packets

Therefore, the command should be executed with sudo. It should look like the following,

 $ sudo ping -i 0.5

Enter the password when you are prompted and the command should work.

Change ping packet size

The default ping packet size is 56 bytes. You can change it through the following command:

$ ping -s packetsize hostname/IP

Here we are setting the packet size to 100; you can see the value set to 100 in the first line of output:

Change ping packet size

Set ping to send a desired number of packets

You can set ping to send a desired number of packets as follows:

$ ping -c NumberOfPackets IP/hostname

In the following example, we are setting the number of packets as 5; after that, the results will end:

Set ping to send a desired number of packets

Flooding the network

Ping command allows super users to send 100 or more packets per second through the following command:

$ sudo ping -f hostname-IP

Flooding the network

Ping prints a “.” when sending a ping and “/” when receiving one.

Set ping timeout

You can set a time limit after which ping will exit; no matter how many ping packets are sent or received:

$ ping -w timeinseconds hostname/ip

Here we are using 3 seconds as timeout:

Set ping timeout

Audible ping

The ping command can be set to play a beep to check whether the host is available as follows:

$ ping -a hostname/ip

Practicing around with this tutorial will enable you to run ping commands to check your network performance in an optimal way. You can also use advanced switches to customize your requests and responses in ping.

The Linux Ping Command