![linux基本命令示例](https://i-blog.csdnimg.cn/blog_migrate/e162eb9c99d17752fedd16f922f2c948.png)
linux基本命令示例
Ping is one of the most used tool for network diagnostics. When internet is not working, can not access file shares etc we will firstly ping command. Ping is one of the most known tool in the IT area. Ping actually uses ICMP packets to get information about network status. In this tutorial we will look practical use cases of Ping tool.
Ping是最常用的网络诊断工具之一。 当互联网无法正常工作,无法访问文件共享等时,我们将首先ping命令。 Ping是IT领域中最知名的工具之一。 Ping实际上使用ICMP数据包来获取有关网络状态的信息。 在本教程中,我们将介绍Ping工具的实际用例。
句法 (Syntax)
Syntax of ping command for Linux is like below.
Linux的ping命令的语法如下。
$ ping [options] [hop1...] destination
帮帮我 (Help)
$ ping -h
![Help](https://i-blog.csdnimg.cn/blog_migrate/2bcf090cc5598730311e6cae5a0697d3.png)
ICMP(ICMP)
ICMP is a network protocol mainly used by ping command. ICMP have different type of messages to exchange network, host, router, switch information. Ping command uses ICMP Request
which is numbered 8 and ICMP Reply
which is numbered 0.
ICMP是主要由ping命令使用的网络协议。 ICMP具有不同类型的消息以交换网络,主机,路由器,交换机信息。 Ping命令使用编号为8的ICMP Request
和编号为0的ICMP Reply
。
平 (Ping)
We will just ping with default settings for ping command. By default ping will work infinitely. We can stop ping command with processes cancel keyboard shortcut CTRL+c
.
我们将使用ping命令的默认设置来ping。 默认情况下,ping将无限工作。 我们可以通过进程取消键盘快捷键CTRL+c
来停止ping命令。
$ ping poftut.com
![Ping](https://i-blog.csdnimg.cn/blog_migrate/8ce41a2619f41b83b24724e60c598c67.png)
After stopping ping command there will be some statistics about ping command. There will be following information
停止ping命令后,将有一些有关ping命令的统计信息。 将有以下信息
Packet transmitted
shows the count of total packet sentPacket transmitted
的Packet transmitted
显示已Packet transmitted
的总数据包数Received
show total count of packets receivedReceived
显示已接收的数据包总数Packet loss
show the percentage of lost or not responded packagesPacket loss
显示丢失或未响应的软件包的百分比Time
shows how long the ping command worked.Time
显示ping命令的工作时间。Rtt min
show minimum round trip time which is how long take a ICMP request and responseRtt min
显示最小往返时间,这是ICMP请求和响应所花费的时间Rtt avg
shows average round trip timeRtt avg
显示平均往返时间Rtt max
shows maximum round trip timeRtt max
显示最大往返时间
增加间隔(Increase Interval)
By default ping command uses 1 second intervals. Interval is the time between two ping or ICMP request. This amount can be changed with -i
option
缺省情况下,ping命令使用1秒间隔。 间隔是两次ping或ICMP请求之间的时间。 可以使用-i
选项更改此金额
$ ping -i 2 poftut.com
![Increase Interval](https://i-blog.csdnimg.cn/blog_migrate/c499e63b5cd48d163357af50e9bd03c3.png)
减少间隔(Decrease Interval)
In previous example we have increased the interval. We can also set lower interval for ping requests. But there is a minor difference. To set interval lower than 0.2 we need root privileges. In this example we will set interval as 0.5 second.
在前面的示例中,我们增加了间隔。 我们还可以为ping请求设置较低的间隔。 但是有微小的区别。 要将间隔设置为小于0.2,我们需要root特权。 在此示例中,我们将间隔设置为0.5秒。
$ ping -i 0.5 poftut.com
![Decrease Interval](https://i-blog.csdnimg.cn/blog_migrate/671e169453128c10b2d1a8b390b8fd14.png)
检查本地接口状态(Check Local Interface Status)
Ping have some diagnostic feature. We can check the status of the local network interface with destination address
Ping具有一些诊断功能。 我们可以使用目标地址检查本地网络接口的状态
$ ping 0
![Check Local Interface Status](https://i-blog.csdnimg.cn/blog_migrate/1c961ce2295714b41c099d2b9e281484.png)
设置数据包计数(Set Packet Count)
As we stated before ping command will work endlessly if there is no interrupt for ping. Providing this interrupt can be difficult job if we use ping as a batch script. We may need to run ping some little time and use the output. In this situations we can set the packet count. Ping will only send specified count. In this example we will send only 3 ping or ICMP requests to the destination.
如前所述,如果没有ping中断,ping命令将无休止地工作。 如果我们使用ping作为批处理脚本,则提供此中断可能很困难。 我们可能需要运行一些时间并使用输出。 在这种情况下,我们可以设置数据包计数。 Ping将仅发送指定的计数。 在此示例中,我们将仅向目的地发送3个ping或ICMP请求。
$ ping -c 3 poftut.com
![Set Packet Count](https://i-blog.csdnimg.cn/blog_migrate/43be46e1e2788dc6782c09d8cbb67630.png)
声音平(Audible Ping)
There are some alert mechanism in the ping command. Ping command can provided some voice alert if some change occur. This change can be the destination host is down or up. But keep in mind that this may not work in some terminals.
ping命令中有一些警报机制。 如果发生某些更改,Ping命令可以提供一些语音警报。 此更改可以是目标主机关闭还是启动。 但是请记住,这可能不适用于某些终端。
$ ping -a poftut.com
![Audible Ping](https://i-blog.csdnimg.cn/blog_migrate/ba48897e5cd329a17d4efd7a4f410461.png)
查找IP地址(Find IP Address)
The IP address will be printed in the first line of ping output if we specify the destination with its host name.
如果我们使用主机名指定目标,则将在ping输出的第一行中显示IP地址。
$ ping poftut.com
![Find IP Address](https://i-blog.csdnimg.cn/blog_migrate/cf60ccd2fbef32d07bea625376af70c7.png)
In this example host name is poftut.com
and related IP address is 45.79.133.118
在此示例中,主机名是poftut.com
,相关的IP地址是45.79.133.118
更改Ping数据包大小 (Change Ping Packet Size)
Ping command uses ICMP packets and puts some meaningless data in the ICMP packet. This data size is 56 byte by default. This data size can be changed with -s
parameter. In this example we will set the data size for ICMP packet 200.
Ping命令使用ICMP数据包,并将一些无意义的数据放入ICMP数据包。 默认情况下,此数据大小为56字节。 可以使用-s
参数更改此数据大小。 在此示例中,我们将设置ICMP数据包200的数据大小。
$ ping -s 200 poftut.com
![Change Ping Packet Size](https://i-blog.csdnimg.cn/blog_migrate/cfaa908a63d271fb28e81b049d6b7cc8.png)
设置生存时间或TTL(Set Time To Live or TTL)
IP packets have Time To Live count. This TTL will set how much hop the packet can transmitted. By using -t
option TTL value can be set. In this example we will set TTL as 22 which is by default 52.
IP数据包具有生存时间计数。 该TTL将设置数据包可以传输多少跳。 通过使用-t
选项,可以设置TTL值。 在此示例中,我们将TTL设置为22,默认情况下为52。
$ ping -t 22 poftut.com
![Set Timeout or Time To Live](https://i-blog.csdnimg.cn/blog_migrate/3e63660a073340f3525201e17cd80d5b.png)
设置超时(Set Timeout)
While sending ICMP request packets we wait for some amount of time for the ICMP response. This waiting time can be change with -w
option. After the timeout value the ping command will exit. In this example we will set timeout value as 2 seconds.
发送ICMP请求数据包时,我们需要等待一段时间才能获得ICMP响应。 可以使用-w
选项更改此等待时间。 在超时值之后,ping命令将退出。 在此示例中,我们将超时值设置为2秒。
$ ping -w 2 poftut.com
![Set Timeout](https://i-blog.csdnimg.cn/blog_migrate/2b547da8e4b6d561beaa56bc64b5e696.png)
设置Ping的路线或路径(Set Route or Path For Ping)
The ICMP packets send by ping command will be routed according to the default routes in the network. Sometimes this default routes will not enough for the test case. In this situations the route information can be provided to the ping command by adding them before the destination. In this example we will set 192.168.122.1
route byte hand. We want to ping destination poftut.com
ping命令发送的ICMP数据包将根据网络中的默认路由进行路由。 有时,这种默认路由对于测试用例而言还不够。 在这种情况下,可以通过在目的地之前添加路由信息来将其提供给ping命令。 在此示例中,我们将设置192.168.122.1
路由字节指针。 我们要ping通目的地poftut.com
$ ping 192.168.122.239 192.168.122.1 poftut.com
But keep in mind that the network devices should be supported host provided routing. This can be a security implication and disabled in the network devices.
但是请记住,网络设备应支持主机提供的路由。 这可能是安全隐患,并且在网络设备中已禁用。
在线Ping工具 (Online Ping Tool)
There are some online ping tools which provided the scale ability to select source host.
有一些在线ping工具提供了选择源主机的扩展能力。
https://asm.ca.com/en/ping.php
https://asm.ca.com/en/ping.php
泛洪ICMP数据包 (Flood ICMP Packets)
Flood is a term used to specify uncontrolled high level network traffic. Ping command can flood ICMP requests to the destination with -f
option. This will generate mass ICMP requests without setting any interval or count. In order to flood we need root privileges.
泛洪是用于指定不受控制的高级网络流量的术语。 Ping命令可以使用-f
选项将ICMP请求泛洪到目标。 这将生成大量ICMP请求,而无需设置任何间隔或计数。 为了泛滥,我们需要root特权。
$ ping -f poftut.com
![Flood](https://i-blog.csdnimg.cn/blog_migrate/c78e5fb36498794a461e1478e7a670c0.png)
As we can see from example there is no verbose information about the ICMP requests. There will be only a summary about the ping command.
从示例中可以看出,没有关于ICMP请求的详细信息。 只会有关于ping命令的摘要。
显示版本 (Show Version)
Ping command version information can be printed with -v
parameter like below.
可以使用-v
参数打印ping命令的版本信息,如下所示。
$ ping -V
![Show Version](https://i-blog.csdnimg.cn/blog_migrate/026abca7d8369da4482d59e53bc29fad.png)
As we can see that ping utility is provided by iputils package which version is s20150815
我们可以看到iputils包提供了ping实用程序,其版本为s20150815
翻译自: https://www.poftut.com/linux-ping-command-tutorial-examples/
linux基本命令示例