linux ping command-泓源视野

linux ping command

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.

努力找了半天,在一篇文章的字里行间发现了 ping 的来历~ 

root@node2:/# apt-get install inetutils-ping

还有ifconfig   可以用 apt-get install net-tools 来安装~ 

或者fping 

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


tcping替代ping来验证服务器是否运行正常

使用tcping

$ tcping
error: Usage: tcping [-q] [-t timeout_sec] [-u timeout_usec] <host> <port>

$ tcping -t 3 www.baidu.com 80

$ echo $?

根据$?的返回值, README里面有详细的说明:

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:

ping

This is the output you will get:

linux ping command插图1

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

OptionDescription
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

linux ping command插图2

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:

linux ping command插图3

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:

linux ping command插图4

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:

linux ping command插图5

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

linux ping command插图6

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:

linux ping command插图7

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.

本文由 泓源视野 作者:admin 发表,其版权均为 泓源视野 所有,文章内容系作者个人观点,不代表 泓源视野 对观点赞同或支持。如需转载,请注明文章来源。
35

发表评论

Protected with IP Blacklist CloudIP Blacklist Cloud
您是第8231466 位访客, 您的IP是:[18.97.14.87]