linux ping command

The Linux Ping Command

Ping or Packet Internet Groper is a network administration utility used to check the connectivity status between a source and a destination computer/device over an IP network. It also helps you assess the time it takes to send and receive a response from the network.

We all have our favorite websites that we frequently visit; if any of these does not load, we really want to know why it happened. Is it because we don’t have an internet connection or is it the issues with our internet service provider preventing us from accessing the website. Another reason might be the unavailability of the website itself. No matter what the reason, the Linux Ping command can provide you with all the answers.

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

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:

aUse this option for a beep sound when the peer is reachable
bUse this option to allow pinging a broadcast address
BUse 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
dUse this option to set the SO-DEBUG option on the socket being used
fUse 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.
nUse this option to display network addresses as numbers rather than as hostnames
qUse 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
vUse this option for verbose output
VUse 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 using 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.

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 super user 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 advance switches to customize your requests and responses in ping.

未经允许不得转载:萌萌guo angline - Apprentissage » linux ping command

赞 (1) 打赏

评论 0

Protected with IP Blacklist CloudIP Blacklist Cloud

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址