Linux shell编程学习笔记66:ping命令 超详细的选项说明

0 前言

网络信息是电脑网络信息安全检查中的一块重要内容,Linux和基于Linux的操作系统,提供了很多的网络命令,今天我们研究最常用的ping命令。

1 ping命令 的功能、格式和选项说明

1.1 ping命令 的功能

简单来说, ping 命令 会使用 ICMP(Internet Control Message Protocol) 传输协议,向网络主机发出要求回应的信息,若网络主机的网络功能没有问题,就会回应该信息,从而得知该主机运作正常。

具体来说,ping 命令使用 ICMP 协议的强制ECHO_REQUEST数据报从主机或网关引出 ICMP ECHO_RESPONSE。ECHO_REQUEST数据报 (''pings'') 都有一个 IP 和 ICMP 标头,后跟一个结构体 timeval,然后是用于填充数据包的任意数量的 ''pad'' 字节。

 ping 命令常用于检测 网络中的另一台主机或路由器是否可访问。

1.2 Linux中的ping命令支持ipV6吗?

  • 在基于 Debian 的 Linux 发行版(包括 Ubuntu)上,您可以使用 ping6 命令强制 ping 使用 IPv6 而不是 IPv4。
  • 在基于 Red Hat 的发行版(如 CentOS)和基于 Arch Linux 的发行版(如 Manjaro)上,使用带 -6 选项的 ping 命令来强制 IPv6。 

1.3 Linux中的ping命令与Windows中的ping命令相同吗?

Linux中的ping命令与Windows中的ping命令在功能上可以说是相同的,但是两者在某些方面存在不同。例如,在默认情况下,Linux 下的ping会连续发送包,而Windows的ping命令 仅发送 4 个包。 

Windows 中的ping命令格式如下:

C:\Users\purpleendurer>ping

用法: ping [-t] [-a] [-n count] [-l size] [-f] [-i TTL] [-v TOS]
            [-r count] [-s count] [[-j host-list] | [-k host-list]]
            [-w timeout] [-R] [-S srcaddr] [-c compartment] [-p]
            [-4] [-6] target_name

选项:
    -t             Ping 指定的主机,直到停止。
                   若要查看统计信息并继续操作,请键入 Ctrl+Break;
                   若要停止,请键入 Ctrl+C。
    -a             将地址解析为主机名。
    -n count       要发送的回显请求数。
    -l size        发送缓冲区大小。
    -f             在数据包中设置“不分段”标记(仅适用于 IPv4)。
    -i TTL         生存时间。
    -v TOS         服务类型(仅适用于 IPv4。该设置已被弃用,
                   对 IP 标头中的服务类型字段没有任何
                   影响)。
    -r count       记录计数跃点的路由(仅适用于 IPv4)。
    -s count       计数跃点的时间戳(仅适用于 IPv4)。
    -j host-list   与主机列表一起使用的松散源路由(仅适用于 IPv4)。
    -k host-list    与主机列表一起使用的严格源路由(仅适用于 IPv4)。
    -w timeout     等待每次回复的超时时间(毫秒)。
    -R             同样使用路由标头测试反向路由(仅适用于 IPv6)。
                   根据 RFC 5095,已弃用此路由标头。
                   如果使用此标头,某些系统可能丢弃
                   回显请求。
    -S srcaddr     要使用的源地址。
    -c compartment 路由隔离舱标识符。
    -p             Ping Hyper-V 网络虚拟化提供程序地址。
    -4             强制使用 IPv4。
    -6             强制使用 IPv6。

1.4 ping命令的格式

与我们之前学的大多数linux命令不同,ping命令不支持--help选项。

我们可以使用ping 或 ping -?命令获取ping命令的格式信息。

[purpleendurer @ bash ~] ping
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
             [-W timeout] destination
[purpleendurer @ bash ~] ping -?
Usage: ping [-aAbBdDfhLnOqrRUvV64] [-c count] [-i interval] [-I interface]
            [-m mark] [-M pmtudisc_option] [-l preload] [-p pattern] [-Q tos]
            [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp_option]
            [-w deadline] [-W timeout] [hop1 ...] destination
Usage: ping -6 [-aAbBdDfhLnOqrRUvV] [-c count] [-i interval] [-I interface]
             [-l preload] [-m mark] [-M pmtudisc_option]
             [-N nodeinfo_option] [-p pattern] [-Q tclass] [-s packetsize]
             [-S sndbuf] [-t ttl] [-T timestamp_option] [-w deadline]
             [-W timeout] destination
[purpleendurer @ bash ~] 

1.4.1支持ipV4的ping命令格式

 ping [-aAbBdDfhLnOqrRUvV64] [-c 完成次数] [-i 间隔秒数] [-I 网络界面]
        [-m mark] [-M pmtudisc_option] [-l 前置载入] [-p 范本样式] [-Q tos]
        [-s 数据包大小] [-S sndbuf] [-t 存活数值] [-T 间间戳选项]
        [-w 退出前等待秒数] [-W 执行前等待秒数] [hop1 ...] 目标主机名称或IP地址

1.4.2 支持ipV6的ping命令格式

ping -6 [-aAbBdDfhLnOqrRUvV] [-c 完成次数] [-i 间隔秒数] [-I 网络界面]
             [-l 前置载入]  [-m mark]  [-M pmtudisc_option]
             [-N nodeinfo_option] [-p 范本样式]  [-Q tclass]  [-s 数据包大小]
             [-S sndbuf] [-t 存活数值] [-T 间间戳选项]  [-w 退出前等待秒数] 
             [[-W 执行前等待秒数]  目标主机名称或IP地址 

1.5 ping命令选项说明

ping命令的选项非常多,而且不同版本linux 提供的ping命令选项也不尽相同。

参数描述
-a

Audible ping.

可听到的ping

-A
  1. Adaptive ping.
  2. Interpacket interval adapts to round-trip time, so that effectively not more than one (or more, if preload is set) unanswered probes present in the network.
  3. Minimal interval is 200msec for not super-user.
  4. On networks with low rtt this mode is essentially equivalent to flood mode.

  1. 自适应 ping。
  2. 数据包间间隔适应往返时间,因此网络中实际上不存在超过一个(或多个,如果设置了预加载)未应答的探测器。
  3. 对于非超级用户,最小间隔为 200 毫秒。
  4. 在低 rtt 的网络上,此模式基本上等同于泛洪模式。
-b

Allow pinging a broadcast address.

允许对广播地址进行ping

-B
  1. Do not allow ping to change source address of probes.
  2. The address is bound to one selected when ping starts.

  1. 不允许ping更改探测的来源地址。
  2. 地址绑定到ping启动时选定的一个地址上。
-c count
  1. Stop after sending count ECHO_REQUEST packets.
  2. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.

  1. 发送指定数量的ECHO_REQUEST数据包后停止。
  2. 使用deadline选项,ping等待count个ECHO_REPLY数据包,直到超时。
-d
  1. Set the SO_DEBUG option on the socket being used.
  2. Essentially, this socket option is not used by Linux kernel.

  1. 在使用的套接字上设置SO_DEBUG选项。
  2. 实际上,Linux内核不使用此套接字选项。
-F flow label
  1. Allocate and set 20 bit flow label on echo request packets. (Only ping6).
  2. If value is zero, kernel allocates random flow label.

  1. 在回显请求数据包上分配并设置20位流标签。(仅限ping6)。
  2. 如果值为零,则内核分配随机的流标签。
-f
  1. Flood ping. For every ECHO_REQUEST sent a period ''.'' is printed, while for ever ECHO_REPLY received a backspace is printed.
  2. This provides a rapid display of how many packets are being dropped.
  3. If interval is not given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more.
  4. Only the super-user may use this option with zero interval.

  1. 洪泛ping。对于每个发送的ECHO_REQUEST,打印一个句点“.”,对于每个接收的ECHO_REPLY,打印一个退格符。
  2. 这提供了快速显示丢包数量的方式。
  3. 如果没有给出间隔,它将间隔设置为零,并且以数据包回来的速度输出或者每秒一百次,以两者中较大的为准。
  4. 只有超级用户可以使用此选项和零间隔。
-i interval
  1. Wait interval seconds between sending each packet.
  2. The default is to wait for one second between each packet normally, or not to wait in flood mode.
  3. Only super-user may set interval to values less 0.2 seconds.   

  1. 在发送每个数据包之间等待指定的时间间隔。
  2. 默认情况下,每个数据包之间等待一秒钟,或者在洪泛模式下不等待。
  3. 只有超级用户可以将间隔设置为小于0.2秒的值。
-I interface address
  1. Set source address to specified interface address.
  2. Argument may be numeric IP address or name of device.
  3. When pinging IPv6 link-local address this option is required.

  1. 将源地址设置为指定的接口地址。
  2. 参数可以是数值IP地址或设备名称。
  3. 在ping IPv6链路本地地址时需要此选项。

-l preload

  1. If preload is specified, ping sends that many packets not waiting for reply.
  2. Only the super-user may select preload more than 3.

  1. 如果指定了preload,则ping发送指定数量的数据包而不等待响应。
  2. 只有超级用户可以选择预加载超过3个的数据包。
-L
  1. Suppress loopback of multicast packets.
  2. This flag only applies if the ping destination is a multicast address.

  1. 屏蔽组播数据包的回路。
  2. 这个标志仅适用于ping目的地是一个组播地址的情况。
-n
  1. Numeric output only.
  2. No attempt will be made to lookup symbolic names for host addresses.

  1. 仅输出数值形式。
  2. 不尝试查找主机地址的符号名称。
-p pattern
  1. You may specify up to 16 ''pad'' bytes to fill out the packet you send.
  2. This is useful for diagnosing data-dependent problems in a network.
  3. For example, -p ff will cause the sent packet to be filled with all ones.

  1. 您可以指定最多16个填充字节来填充发送的数据包。
  2. 这对于诊断网络中依赖于数据的问题很有用。
  3. 例如,-p ff将导致发送的数据包全部填充为1。
-Q tos
  1. Set Quality of Service -related bits in ICMP datagrams.
  2. tos can be either decimal or hex number.
  3. Traditionally (RFC1349), these have been interpreted as: 0 for reserved (currently being redefined as congestion control), 1-4 for Type of Service and 5-7 for Precedence. Possible settings for Type of Service are: minimal cost: 0x02, reliability: 0x04, throughput: 0x08, low delay: 0x10.
  4. Multiple TOS bits should not be set simultaneously.
  5. Possible settings for special Precedence range from priority (0x20) to net control (0xe0).
  6. You must be root (CAP_NET_ADMIN capability) to use Critical or higher precedence value.
  7. You cannot set bit 0x01 (reserved) unless ECN has been enabled in the kernel.
  8. In RFC2474, these fields has been redefined as 8-bit Differentiated Services (DS), consisting of: bits 0-1 of separate data (ECN will be used, here), and bits 2-7 of Differentiated Services Codepoint (DSCP).

  1. 设置ICMP数据报中的服务质量相关位。
  2. tos可以是十进制或十六进制数。
  3. 传统上(RFC1349),这些被解释为:0表示保留(目前正在重新定义为拥塞控制),1-4表示服务类型,5-7表示优先级。服务类型的可能设置为:最低成本:0x02,可靠性:0x04,吞吐量:0x08,低延迟:0x10。
  4. 请勿同时设置多个TOS位。
  5. 特殊优先级的可能设置范围从优先级(0x20)到网络控制(0xe0)。
  6. 您必须具有root(CAP_NET_ADMIN权限)才能使用重要或更高优先级的值。
  7. 除非已在内核中启用了ECN,否则不能设置位0x01(保留)。
  8. 在RFC2474中,这些字段已被重新定义为8位区分服务(DS),包括:单独数据的位0-1(这里将使用ECN),以及不同服务代码点(DSCP)的位2-7。
-q
  1. Quiet output.
  2. Nothing is displayed except the summary lines at startup time and when finished.

  1. 静默输出。
  2. 除了启动时和完成时的总结行外,不显示任何内容。
-R
  1. Record route.
  2. Includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on returned packets.
  3. Note that the IP header is only large enough for nine such routes.
  4. Many hosts ignore or discard this option.

  1. 记录路由。
  2. 在ECHO_REQUEST数据包中包含RECORD_ROUTE选项,并在返回的数据包上显示路由缓冲区。
  3. 请注意,IP头部仅足够存储9个此类路由。
  4. 许多主机忽略或丢弃此选项。
-r
  1. Bypass the normal routing tables and send directly to a host on an attached interface.
  2. If the host is not on a directly-attached network, an error is returned.
  3. This option can be used to ping a local host through an interface that has no route through it provided the option -I is also used.

  1. 绕过正常路由表,直接发送到连接的主机。
  2. 如果主机不在直接连接的网络上,则返回错误。
  3. 使用选项-I可以通过没有路由的接口ping本地主机。
-s packetsize
  1. Specifies the number of data bytes to be sent.
  2. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.

  1. 指定要发送的数据字节数。
  2. 默认为56个字节,与8个字节的ICMP头数据组合在一起,总共是64个ICMP数据字节。
-S sndbuf
  1. Set socket sndbuf.
  2. If not specified, it is selected to buffer not more than one packet.    

  1. 设置套接字的sndbuf。
  2. 如果未指定,则选择的缓冲区不超过一个数据包。
-t ttl

Set the IP Time to Live.

设置IP的生存时间(TTL)

-T timestamp option
  1. Set special IP timestamp options.
  2. timestamp option may be either tsonly (only timestamps), tsandaddr (timestamps and addresses) or tsprespec host1 [host2 [host3 [host4]]] (timestamp prespecified hops).

  1. 设置特殊的IP时间戳选项。
  2. 时间戳选项可以是tsonly(仅时间戳),tsandaddr(时间戳和地址)或tsprespec host1 [host2 [host3 [host4]]](预指定时间戳跳数)。
-M hint
  1. Select Path MTU Discovery strategy.
  2. hint may be either do (prohibit fragmentation, even local one), want (do PMTU discovery, fragment locally when packet size is large), or dont (do not set DF flag).

  1. 选择路径MTU发现策略。
  2. 提示可以是do(禁止分段,即使是本地分段),want(进行PMTU发现,当数据包大小较大时在本地分段),或dont(不设置DF标志)。
-U
  1. Print full user-to-user latency (the old behaviour).
  2. Normally ping prints network round trip time, which can be different f.e. due to DNS failures.

  1. 打印完整的用户到用户延迟(旧行为)。
  2. 通常,ping打印网络往返时间,这可以与由于DNS故障等原因不同。
-v

Verbose output.

详细输出

-V

Show version and exit.

显示版本并退出

-w deadline
  1. Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received.
  2. In this case ping does not stop after count packet are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network.

  1. 指定超时时间(秒),在此时间内ping无论发送或接收到多少个数据包都会退出。
  2. 在这种情况下,ping不会在发送count个数据包后停止,它会等待deadline到期或直到接收到count个探测的响应或接收到某些来自网络的错误通知。
-W timeout
  1. Time to wait for a response, in seconds.
  2. The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.

  1. 等待响应的时间(秒)。
  2. 该选项仅在没有收到任何响应的情况下影响超时,否则ping等待两个往返时间。

2 ping命令实例

2.1 ping -a g.cn

[purpleendurer @ bash ~] ping -a g.cn
PING g.cn (114.250.67.34) 56(84) bytes of data.
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=1 ttl=116 time=4.41 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=2 ttl=116 time=4.36 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=3 ttl=116 time=4.34 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=4 ttl=116 time=4.38 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=5 ttl=116 time=4.34 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=6 ttl=116 time=4.36 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=7 ttl=116 time=4.36 ms
^C
--- g.cn ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6007ms
rtt min/avg/max/mdev = 4.342/4.368/4.414/0.041 ms
[purpleendurer @ bash ~] 

1.2 ping -A g.cn :自适应 ping g.cn

[purpleendurer @ bash ~] ping -A g.cn
PING g.cn (114.250.70.34) 56(84) bytes of data.
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=1 ttl=117 time=5.04 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=2 ttl=117 time=4.76 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=3 ttl=117 time=4.76 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=4 ttl=117 time=4.77 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=5 ttl=117 time=4.76 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=6 ttl=117 time=4.81 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=7 ttl=117 time=4.77 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=8 ttl=117 time=4.79 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=9 ttl=117 time=4.98 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=10 ttl=117 time=4.81 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=11 ttl=117 time=4.77 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=12 ttl=117 time=4.78 ms
^C
--- g.cn ping statistics ---
12 packets transmitted, 12 received, 0% packet loss, time 2210ms
rtt min/avg/max/mdev = 4.760/4.820/5.045/0.123 ms, ipg/ewma 200.918/4.862 ms
[purpleendurer @ bash ~] 

 

可以看到,ping -A 返回个信息的速度明显快于  ping -a。

1.3 ping -b  g.cn:使用广播方式ping g.cn

[purpleendurer @ bash ~] ping -b  g.cn
PING g.cn (114.250.70.34) 56(84) bytes of data.
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=1 ttl=117 time=4.83 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=2 ttl=117 time=4.81 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=3 ttl=117 time=4.80 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=4 ttl=117 time=4.76 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=5 ttl=117 time=4.80 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=6 ttl=117 time=4.86 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=7 ttl=117 time=4.80 ms
^C
--- g.cn ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6011ms
rtt min/avg/max/mdev = 4.766/4.813/4.862/0.095 ms
[purpleendurer @ bash ~] 

 

1.4 ping -B  g.cn

[purpleendurer @ bash ~] ping -B  g.cn
PING g.cn (114.250.67.34) from 172.25.109.185 : 56(84) bytes of data.
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=1 ttl=116 time=4.01 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=2 ttl=116 time=4.36 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=3 ttl=116 time=3.94 ms
^C
--- g.cn ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 3.943/4.108/4.364/0.197 ms
[purpleendurer @ bash ~] 

 

 

1.5 ping -c 2 g.cn:向g.cn发送2个ICMP包

[purpleendurer @ bash ~] ping -c 2 g.cn
PING g.cn (114.250.70.34) 56(84) bytes of data.
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=1 ttl=117 time=4.82 ms
64 bytes from 114.250.70.34 (114.250.70.34): icmp_seq=2 ttl=117 time=4.82 ms

--- g.cn ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 4.822/4.822/4.822/0.000 ms
[purpleendurer @ bash ~] 

 

1.6 ping -d  g.cn

[purpleendurer @ bash ~] ping -d  g.cn
PING g.cn (114.250.67.34) 56(84) bytes of data.
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=1 ttl=116 time=3.95 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=2 ttl=116 time=3.97 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=3 ttl=116 time=3.92 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=4 ttl=116 time=3.89 ms
64 bytes from 114.250.67.34 (114.250.67.34): icmp_seq=5 ttl=116 time=3.92 ms
^C
--- g.cn ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 3.896/3.933/3.976/0.062 ms
[purpleendurer @ bash ~] 

 

1.7 ping -f g.cn:洪水 ping g.cn (只有超级用户才能使用此选项)

[purpleendurer @ bash ~] ping -f g.cn
PING g.cn (114.250.67.34) 56(84) bytes of data.
ping: cannot flood; minimal interval allowed for user is 200ms
[purpleendurer @ bash ~] sudo ping -f g.cn
PING g.cn (114.250.65.34) 56(84) bytes of data.
.^C
--- g.cn ping statistics ---
5304 packets transmitted, 5303 received, 0% packet loss, time 28698ms
rtt min/avg/max/mdev = 5.285/5.390/12.965/0.268 ms, pipe 2, ipg/ewma 5.411/5.371 ms
[purpleendurer @ bash ~] 

1.8 ping -i 2 -c 3 g.cn:间隔2秒钟向g.cn发送3个ICMP包

[purpleendurer @ bash ~] ping -i 2 -c 3 g.cn
PING g.cn (114.250.65.34) 56(84) bytes of data.
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=1 ttl=117 time=5.49 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=2 ttl=117 time=5.38 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=3 ttl=117 time=5.40 ms

--- g.cn ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 4005ms
rtt min/avg/max/mdev = 5.389/5.428/5.491/0.096 ms
[purpleendurer @ bash ~] 

 

1.9 ping -q g.cn :以静默方式ping g.cn

[purpleendurer @ bash ~] ping -q g.cn
PING g.cn (114.250.65.34) 56(84) bytes of data.
^C
--- g.cn ping statistics ---
8 packets transmitted, 8 received, 0% packet loss, time 7010ms
rtt min/avg/max/mdev = 5.386/5.410/5.453/0.023 ms
[purpleendurer @ bash ~] 

 

命令返回的信息除了启动时和完成时的总结行外,不显示任何内容。 

1.10 ping -s 99 g.cn:以99个字节ping g.cn

[purpleendurer @ bash ~] ping -s 99 g.cn
PING g.cn (114.250.65.34) 99(127) bytes of data.
107 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=1 ttl=117 time=5.43 ms
107 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=2 ttl=117 time=5.44 ms
107 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=3 ttl=117 time=5.39 ms
^C
--- g.cn ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 5.396/5.427/5.449/0.088 ms
[purpleendurer @ bash ~] 

 

1.11 ping -t 16 g.cn: 以TTL 值为16向g.cn发送ICMP包

[purpleendurer @ bash ~] ping -t 16 g.cn
PING g.cn (114.250.65.34) 56(84) bytes of data.
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=1 ttl=117 time=5.39 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=2 ttl=117 time=5.40 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=3 ttl=117 time=5.38 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=4 ttl=117 time=5.39 ms
^C
--- g.cn ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 5.382/5.393/5.407/0.090 ms
[purpleendurer @ bash ~] 

 1.12 ping -T <时间戳>  g.cn:设置特殊的 IP 时间戳选项来ping g.cn

[purpleendurer @ bash ~] ping -T tsandaddr  g.cn
PING g.cn (114.250.66.34) 56(124) bytes of data.
^C
--- g.cn ping statistics ---
8 packets transmitted, 0 received, 100% packet loss, time 7166ms

[purpleendurer @ bash ~] ping -T tsonly  g.cn
PING g.cn (114.250.66.34) 56(124) bytes of data.
^C
--- g.cn ping statistics ---
5 packets transmitted, 0 received, 100% packet loss, time 4091ms

[purpleendurer @ bash ~] 

 

1.13 ping -v g.cn:启用详细模式ping g.cn

[purpleendurer @ bash ~] ping -v g.cn
PING g.cn (114.250.65.34) 56(84) bytes of data.
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=1 ttl=117 time=5.51 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=2 ttl=117 time=5.40 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=3 ttl=117 time=5.37 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=4 ttl=117 time=5.45 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=5 ttl=117 time=5.35 ms
64 bytes from 114.250.65.34 (114.250.65.34): icmp_seq=6 ttl=117 time=5.41 ms
^C
--- g.cn ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 5006ms
rtt min/avg/max/mdev = 5.358/5.420/5.516/0.100 ms
[purpleendurer @ bash ~] 

 

好像没有显示什么更详细的信息 

3 参考资料

 ping(8) - Linux man page (die.net)

  • 24
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

紫郢剑侠

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值