< Home

ping

Function

The ping command checks whether a specified IPv4 address is reachable and exports corresponding statistics.

Format

ping [ ip ] [ -a source-ip-address | -c count | -d | { -f | ignore-mtu } | -h ttl-value | -nexthop nexthop-ip-address | -i interface-type interface-number | -m time | -n | -name | -p pattern | -q | -r | { -s packetsize | -range [ min min-size | max max-size | step step-size ] * } | -system-time | -t timeout | -tos tos-value | -v | -vpn-instance vpn-instance-name ] * host [ ip-forwarding ]

Parameters

Parameter Description Value

ip

Indicates the IPv4 protocol. If ip is not specified, the IPv4 protocol is used.

-

-a source-ip-address

Specifies the source IP address of the ICMP Echo Request message. If the source IP address is not specified, the IP address of the outbound interface is used as the source IP address of the ICMP Echo Request message.

The value is in dotted decimal notation.

-c count

Specifies the number of times for sending ICMP Echo Request messages.

The ping command labels each ICMP Echo Request message with a sequence ID that starts from 1 and is increased by 1. By default, five ICMP Echo Request messages are sent. You can set the number of ICMP Echo Request messages to send by specifying the parameter count, that is, performing a Ping test with multiple Ping packets.

In the case of poor network quality, you can set this parameter to a comparatively large value to check the network quality based on the packet loss rate.

The value is an integer that ranges from 1 to 4294967295. The default value is 5.

-d

Indicates that the socket works in debug mode.

By default, the socket works in non-debug mode.

-f

Indicates that packets are not fragmented during transmission.

NOTE:

After this parameter is specified, ICMP packets are not fragmented. If the ICMP packet size exceeds the link MTU, the ICMP packet is discarded. If you do not want ICMP packets to be discarded, do not specify this parameter or increase the link MTU.

-

-h ttl-value

Specifies the TTL value.

If the TTL field is reduced to 0 during message forwarding, the Layer 3 device that the message reaches sends an ICMP timeout message to the source host, indicating that the destination host is unreachable.

The value is an integer that ranges from 1 to 255. The default value is 255.

-nexthop nexthop-ip-address

Specifies an IP address for the next hop.

If you have specified this parameter, the device no longer searches the routing table before sending ICMP Echo Response packets. This process prevents ping failures caused by incorrect routing entries.

NOTE:

The specified next hop address must be the next hop address of a directly connected physical interface.

When you specify a next hop address, you can configure -i interface-type interface-number to specify an outbound interface. The following conditions must be met to ensure a test success: the specified next hop address must match the outbound interface; the specified outbound interface cannot be a logical interface's member interface.

If you have specified a next hop address, you cannot specify a VPN.

The value is in dotted decimal notation.

-i interface-type interface-number

Specifies the outbound interface for sending ICMP Echo Request packets.

NOTE:

In load balancing scenarios, if an interface is specified to send ICMP Echo Request packets, all packets are sent from the interface and load balancing is not performed.

The interface specified to send ICMP Echo Request packets must be a Layer 3 interface, such as a VLANIF interface.

-

-m time

Specifies the time to wait before sending the next ICMP Echo Request message.

Each time the source sends an ICMP Echo Request message using the ping command, the source waits a period of time (500 ms by default) before sending the next ICMP Echo Request message. You can set the time to wait before sending the next ICMP Echo Request message using the parameter time. In the case of poor network condition, the value should be equal to or larger than 500, in milliseconds.

The value is an integer that ranges from 1 to 10000, in milliseconds. The default value is 500.

-n

Uses the value of host as the IP address to spare domain name resolution.

-

-name

Displays the name of the destination host.

-

-p pattern

Specifies pad characters for ICMP Echo Request messages.

By configuring pad characters for ICMP Echo Request messages, you can identify a specific message among the large number of received ICMP Echo Reply messages.

The value is a hexadecimal integer that ranges from 0 to FFFFFFFF. By default, the padding starts from 0x01, and continues in ascending order.

-q

Displays only the statistics. If the ping command carries this parameter, the system displays only the statistics information such as the number of sent and received packets, packet loss rate, and minimum, average, and maximum RTTs of the packet.

By default, the system displays all statistics information.

-r

Records the route along which an IP packet is forwarded.

When -r is specified, during the transmission of an IP packet, the IP address of each Layer 3 device that the IP packet passes through is added to the Options field. When the IP packet reaches the destination, all IP addresses recorded in the Options field are copied to the ICMP Echo Reply message. In addition, the IP address of each Layer 3 device that the returned IP packet passes through is added to the message. When the ping program receives the ICMP Echo Reply message, IP addresses of the passed Layer 3 devices are displayed.

By default, the route along which an IP packet is forwarded is not recorded.

-s packetsize

Specifies the length of an ICMP Echo Request message, excluding the IP header and ICMP header, that is, performing a Ping test with large-sized Ping packets.

The value is an integer that ranges from 20 to 9600, in bytes. The default value is 56.

-range

Enables the device to send ICMP Echo Request messages with variable payload lengths.

NOTE:

The command execution takes a long period if a large number of ICMP Echo Request messages need to be sent. If you want to terminate the command execution, press Ctrl+C.

To change the number of ICMP Echo Request messages to be sent, change the values of min min-size and max max-size. The value of min min-size must be smaller than that of max max-size.

If both the -range and -c count parameters are specified, the device sends ICMP Echo Request messages of the same payload length for the number of times specified by the -c count parameter.

  • If the -range parameter is not specified, the payload length of an ICMP Echo Request message is equal to the length specified by the -s packetsize parameter. The default value is 56, in bytes.
  • If the -range parameter is specified, the payload length of the first ICMP Echo Request message is min min-size, and that of the second ICMP Echo Request message is min min-size plus step step-size. The payload length increases incrementally by step step-size for subsequent ICMP Echo Request messages until max max-size is reached. After that, the device will not send ICMP Echo Request messages any more.

    By default, the payload length of an ICMP Echo Request message ranges from 56 to 9600 bytes, and the step length is 1 byte.

min min-size

Specifies the minimum payload length of an ICMP Echo Request message.

The value is an integer ranging from 20 to 9600, in bytes. The default value is 56.

max max-size

Specifies the maximum payload length of an ICMP Echo Request message.

The value is an integer ranging from 20 to 9600, in bytes. The default value is 9600.

step step-size

Specifies the step length of an ICMP Echo Request message.

The value is an integer ranging from 1 to 1000, in bytes. The default value is 1.

-system-time

Displays the system time when the ping packet is sent.

-

-t timeout

Specifies the timeout period to wait for an ICMP Echo Reply message after an ICMP Echo Request message is sent.

After the ping command is run, the source sends an ICMP Echo Request message to a destination and waits for an ICMP Echo Reply message. If the destination, after receiving the ICMP Echo Request message, returns an ICMP Echo Reply message to the source within the period specified by the parameter timeout, the destination is reachable. If the destination does not return an ICMP Echo Reply message within the specified period, the source displays that the message times out.

Normally, the source receives an ICMP Echo Reply message within 1 to 10 seconds after sending an ICMP Echo Request message. If the transmission speed is low, properly prolong the timeout period.

The value is an integer that ranges from 0 to 65535, in milliseconds. The default value is 2000.

-tos tos-value

Specifies the ToS value of the sent ICMP Echo Request messages. The ToS value is used to set the packet priority.

The value is an integer that ranges from 0 to 255. The default value is 0.

-v

  • If -v is not specified, the system displays only the ICMP Echo Reply messages received by the local user.
  • If -v is specified, the system displays all received ICMP Echo Reply messages.

-

-vpn-instance vpn-instance-name

Specifies the name of a VPN instance.

The value must be an existing VPN instance name.

ignore-mtu

Indicates that the system does not check the interface MTU when a packet is sent.

-

host

Specifies the domain name or IP address of the destination host.

The value is a string of 1 to 255 case-sensitive characters with spaces not supported. When double quotation marks are used around the string, spaces are allowed in the string. Alternatively, the value can be a valid IPv4 address in dotted decimal notation.

ip-forwarding

Indicates that the ping packets are forcibly forwarded through IP on the first node.

-

Views

All views

Default Level

0: Visit level

Usage Guidelines

Usage Scenario

The ping command is a common debugging tool for testing the network connectivity by transmitting ICMP Echo messages. It can detect the following items:

  • Availability of the remote device
  • Round-trip delay in communication between the local and remote devices
  • Packet loss rate
You can run the ping command to check the network connectivity or line quality in the following scenarios:
  • Scenario 1: Check the protocol stack on the local device. You can run the ping loopback-address command to check whether the TCP/IP protocol stack works properly on the local device.
  • Scenario 2: Check whether the destination host is reachable on an IP network. You can run the ping host command to send an ICMP Echo Request message to the destination host. If a reply is received, the destination host is reachable.
  • Scenario 3: In the case of an unstable network, you can run the ping -c count -t timeout host command to check the quality of the network between the local device and the peer. By analyzing the packet loss rate and average delay in the command output, you can evaluate the network quality. If the network is unreliable, set the packet transmission count (-c) and timeout (-t) to the upper limits. This makes the test result accurate.

  • Scenario 4: Check the path. You can run the ping -r host command to obtain information about nodes along the path from the local device to the peer.

  • Scenario 5: Check the path MTU. You can run the ping -f -s packetsize host command to prevent ICMP message fragmentation and set the length of an ICMP message so as to obtain the path MTU through multiple probes.
  • Scenario 6: Check whether the peer is reachable on a Layer 3 VPN. On a Layer 3 VPN, devices may not have routing information about each other. Therefore, you cannot use the ping host command to check whether the peer is reachable. When a VPN instance name is specified, you can run the ping -vpn-instance vpn-instance-name host command to send an ICMP Echo Request message to the peer. If the peer returns an ICMP Echo Reply message, the peer is reachable.

Prerequisite

  • Before running the ping command, ensure that the ICMP module is working properly.
  • If -vpn-instance is specified, ensure that the VPN module is working properly.

Precautions

  • If an intermediate device is disabled from responding to ICMP messages, detection on this node fails.
  • If a fault occurs in the ping process, you can press Ctrl+C to terminate the ping operation.
  • To ensure security, do not ping the broadcast address, such as XX.XX.XX.255.
  • When the destination host is unreachable, the system displays "Request time out", which indicates that the ICMP Echo Request message times out.
  • The ping command is typically used to check network connectivity and link quality, and cannot be used to evaluate the forwarding latency of a switch. If the pinged IP address is not the local switch's, the switch forwards the ICMP packet according to routing entries, without sending them to the CPU. If the pinged IP address is the local switch's, the switch sends the ICMP packets to the CPU for processing. In this case, you can run the icmp-reply fast command on the switch to enable the fast ICMP reply function. With this function, the switch directly processes the ICMP packets destined for its own IP address on interfaces, without sending the packets to the CPU. This minimizes the ping latency.

Example

# Check whether the host at 10.1.1.2 is reachable.

<HUAWEI> ping 10.1.1.2
  PING 10.1.1.2: 56  data bytes, press CTRL_C to break
    Reply from 10.1.1.2: bytes=56 Sequence=1 ttl=255 time=2 ms
    Reply from 10.1.1.2: bytes=56 Sequence=2 ttl=255 time=1 ms
    Reply from 10.1.1.2: bytes=56 Sequence=3 ttl=255 time=1 ms
    Reply from 10.1.1.2: bytes=56 Sequence=4 ttl=255 time=1 ms
    Reply from 10.1.1.2: bytes=56 Sequence=5 ttl=255 time=1 ms
  --- 10.1.1.2 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 1/1/2 ms 

# Check whether the host at 10.1.1.4 is reachable, set the transmission count to 8, and set the period for waiting for an ICMP Echo Reply message to 4000 ms.

<HUAWEI> ping -c 8 -t 4000 10.1.1.4
  PING 10.1.1.4: 56  data bytes, press CTRL_C to break
    Reply from 10.1.1.4: bytes=56 Sequence=1 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=2 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=3 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=4 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=5 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=6 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=7 ttl=255 time=32 ms
    Reply from 10.1.1.4: bytes=56 Sequence=8 ttl=255 time=32 ms
  --- 10.1.1.4 ping statistics ---
    8 packet(s) transmitted
    8 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 32/32/32 ms

# Enable the device to send ICMP Echo Request messages with variable payload lengths.

<HUAWEI> ping -range min 56 max 60 192.168.1.9
  PING 192.168.1.9: 56-60  data bytes, press CTRL_C to break
    Reply from 192.168.1.9: bytes=56 Sequence=1 ttl=255 time=80 ms
    Reply from 192.168.1.9: bytes=57 Sequence=2 ttl=255 time=60 ms
    Reply from 192.168.1.9: bytes=58 Sequence=3 ttl=255 time=80 ms
    Reply from 192.168.1.9: bytes=59 Sequence=4 ttl=255 time=80 ms
    Reply from 192.168.1.9: bytes=60 Sequence=5 ttl=255 time=50 ms

  --- 192.168.1.9 ping statistics ---
    5 packet(s) transmitted
    5 packet(s) received
    0.00% packet loss
    round-trip min/avg/max = 50/70/80 ms   

# Check whether the host at 10.1.1.10 is reachable.

<HUAWEI> ping 10.1.1.10
ping 10.1.1.10                                                                                                          
  PING 10.1.1.10: 56  data bytes, press CTRL_C to break
    Reply from 10.1.1.10: bytes=56 Sequence=1 ttl=128 time=1 ms
    Reply from 10.1.1.10: bytes=56 Sequence=1 ttl=64 time=1 ms (DUP!)
    Reply from 10.1.1.10: bytes=56 Sequence=2 ttl=128 time=1 ms                                                                      
    Reply from 10.1.1.10: bytes=56 Sequence=2 ttl=64 time=1 ms (DUP!)                                                                
    Reply from 10.1.1.10: bytes=56 Sequence=3 ttl=128 time=1 ms
    Reply from 10.1.1.10: bytes=56 Sequence=3 ttl=64 time=1 ms (DUP!)
    Reply from 10.1.1.10: bytes=56 Sequence=4 ttl=128 time=1 ms                                                                      
    Reply from 10.1.1.10: bytes=56 Sequence=4 ttl=64 time=1 ms (DUP!)                                                                
    Reply from 10.1.1.10: bytes=56 Sequence=5 ttl=128 time=1 ms                                                                      
                                                                                                                                    
  --- 10.1.1.10 ping statistics ---                                                                                                  
    5 packet(s) transmitted                                                                                                         
    9 packet(s) received                                                                                                            
    4 duplicates                                                                                                                    
    -- somebody's printing up packets                                                                                               
    round-trip min/avg/max = 1/0/1 ms     
Table 1 Description of the ping command output

Item

Description

PING x.x.x.x

Reachability of the destination host with the IP address as x.x.x.x is tested.

x data bytes

Length of a sent ICMP Echo Request message.

press CTRL_C to break

The ongoing ping test is terminated after you press Ctrl+C.

Reply from x.x.x.x

The destination host responds to the ICMP Echo Request message with an ICMP Echo Reply message that contains the following items:
  • bytes: indicates the length of the ICMP Echo Reply message.

  • Sequence: indicates the sequence number of the ICMP Echo Reply message.

  • ttl: indicate the TTL value of the ICMP Echo Reply message.

  • time: indicates the RTT, in milliseconds.

If no ICMP Echo Reply message is received after the timeout period, the system displays "Request time out".
NOTE:

If a received packet ends with (DUP!), the device has received the Echo Reply messages with repeated sequence number.

x.x.x.x ping statistics

Statistics collected after the ping test on the destination host. The statistics include the following information:
  • packet(s) transmitted: indicates the number of sent ICMP Echo Request messages.

  • packet(s) received: indicates the number of received ICMP Echo Reply messages.

  • duplicates: indicates that the device has received the Echo Reply messages with repeated sequence number.

  • % packet loss: indicates the percentage of unresponded messages to total sent messages.

  • -- somebody's printing up packets: indicates that the number of received Echo Reply messages is larger than the number of send Echo Request messages.

  • round-trip min/avg/max: indicates the minimum, average, and maximum RTTs. The unit is ms. (On an IPv4 network, round-trip min/avg/max is not displayed if the ping fails. On an IPv6 network, round-trip min/avg/max = 0/0/0 ms is displayed if the ping fails.)

Copyright © Huawei Technologies Co., Ltd.
Copyright © Huawei Technologies Co., Ltd.
< Previous topic Next topic >