赞
踩
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 of ping command for Linux is like below.
Linux的ping命令的语法如下。
$ ping [options] [hop1...] destination
$ ping -h
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
。
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
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 sent
Packet transmitted
的Packet transmitted
显示已Packet transmitted
的总数据包数
Received
show total count of packets received
Received
显示已接收的数据包总数
Packet loss
show the percentage of lost or not responded packages
Packet 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 response
Rtt min
显示最小往返时间,这是ICMP请求和响应所花费的时间
Rtt avg
shows average round trip time
Rtt avg
显示平均往返时间
Rtt max
shows maximum round trip time
Rtt max
显示最大往返时间
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
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
Ping have some diagnostic feature. We can check the status of the local network interface with destination address
Ping具有一些诊断功能。 我们可以使用目标地址检查本地网络接口的状态
$ ping 0
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
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
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
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 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
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
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
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.
但是请记住,网络设备应支持主机提供的路由。 这可能是安全隐患,并且在网络设备中已禁用。
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
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
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命令的摘要。
Ping command version information can be printed with -v
parameter like below.
可以使用-v
参数打印ping命令的版本信息,如下所示。
$ ping -V
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基本命令示例
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。