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.
努力找了半天，在一篇文章的字里行间发现了 ping 的来历～
root@node2:/# apt-get install inetutils-ping
还有ifconfig 可以用 apt-get install net-tools 来安装～
fping 192.168.0.1 192.168.0.125 192.168.0.126 2>/dev/null
fping -g 192.168.1.0/24 2>/dev/null
error: Usage: tcping [-q] [-t timeout_sec] [-u timeout_usec] <host> <port>
$ tcping -t 3 www.baidu.com 80
$ echo $?
Return values to the shell are:
-1 an error occured
0 port is open
1 port is closed
2 connection establishment timed out
Using the Ping command
In the Linux terminal type the following command:
This is the output you will get:
Let us describe(in alphabetic order) the commonly used options that you can see above:
|Use this option for a beep sound when the peer is reachable
|Use this option to allow pinging a broadcast address
|Use this option if you do not want to allow the ping to change the source address of the probe
|Use this option to set the number of times to send the ping request
|Use this option to set the SO-DEBUG option on the socket being used
|Use this option to flood the network by sending hundred or more packets per second
|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.
|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.
|Use this option to display network addresses as numbers rather than as hostnames
|Use this option to display a quiet output. It means that only the summary is displayed at startup and finish time
|Use this option to set the Time To Live
|Use this option for verbose output
|Use this option to display the version and exit
|Use this option to specify a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received.
|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
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 127.0.0.1
Here is an example to decrease the time interval between two pings:
$ ping -i 0.5 127.0.0.1
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:
Therefore, the command should be executed with sudo. It should look like the following,
$ sudo ping -i 0.5 127.0.0.1
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:
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:
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
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:
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.