Ping and Tracert
This section describes how to use Ping and Tracert commands to check network connectivity and locate network faults. The Ping command checks network connectivity and host reachability and the Tracert command tracks the gateways that packets pass through from the source host to the destination host.
Introduction to the Ping Command
Based on the Internet Control Message Protocol (ICMP), the Ping command is used to check network connectivity and host reachability. The source sends an ICMP Echo Request message to the destination, and determines reachability. The source determines the quality of the link from which the destination is reachable based on the number of sent ICMP Echo Request messages and received ICMP Echo Response messages, and the round-trip time (RTT) of ping packets.
Ping Command Format
Command Reference provides detailed description of command parameters and usage. Here lists only some commonly used parameters and their descriptions.
ping [ ip ] [ -a source-ip-address | -c count | -f | -s packetsize | -t timeout ] *host
- -a: specifies the source IP address for sending Echo Request messages. If no source IP address is specified, the IP address of the outbound interface is used as the source IP address.
- -c: specifies the count for sending Echo Request messages. The default value is 5. You can increase the number of outgoing packets to detect the network quality based on the packet loss ratio.
- -f: indicates that packets are not fragmented when they are sent. The device discards the packets if the packet size exceeds the MTU.
- -s: specifies the length of an Echo Request message without the IP header and ICMP header.
- -t: specifies the timeout interval of Echo Response messages. You can set a larger timeout interval if the network is unstable. The default value is 2s. If the device receives no Echo Request message, it determines that the destination is unreachable.
- host: indicates an IP address or a domain name. If it is a domain name, the device performs DNS resolution and displays the resolved IP address.
You can use the parameters -s and -f simultaneously to test the path MTU (PMTU). For example, if the ping operation succeeds when the parameter -s is set to 1472 but fails when the parameter is set to 1473, the PMTU is 1500, which is the total sum of 1472, 20 (IP header), and 8 (ICMP header).
The ping function varies with the operating system of a PC. The Windows operating system is used as an example.
ping [ -n number ] [ -t ] [ -l number ] [ -f ] [ -a ] ip-address
- -n: specifies the number of ping packets. The default value is 5.
- -t: indicates that the source sends Echo Request messages to the destination continuously until manual operations are involved. You can press Ctrl+Break to temporarily stop the ping command and view the statistics, and press Ctrl+C to end the ping operation.
- -l: specifies the number of bytes of data in ping packets. The value ranges from 0 to 65500.
- -f: indicates that packets are not fragmented when they are sent. The device discards the packets if the packet size exceeds the MTU.
- -a: indicates that the device resolves an IP address into a host name.
Description of the Ping Command Output
<Huawei> ping 10.135.18.118 PING 10.135.18.118: 56 data bytes, press CTRL_C to break Reply from 10.135.18.118: bytes=56 Sequence=1 ttl=255 time=1 ms Reply from 10.135.18.118: bytes=56 Sequence=2 ttl=255 time=1 ms Reply from 10.135.18.118: bytes=56 Sequence=3 ttl=255 time=2 ms Reply from 10.135.18.118: bytes=56 Sequence=4 ttl=255 time=1 ms Reply from 10.135.18.118: bytes=56 Sequence=5 ttl=255 time=2 ms --- 10.135.18.118 ping statistics --- 5 packet(s) transmitted 5 packet(s) received 0.00% packet loss round-trip min/avg/max = 1/1/2 ms
In this example:
- The device sends five ping packets and receives response for all the five packets.
- The ping packets use the default size, 56 bytes.
- The TTL value is 255, indicating that the source is directly connected to the destination.
- The time is 1 ms, indicating that the device receives an Echo Response message 1 ms after it sends an Echo Request message. This parameter can be used as a reference to determine whether the network is congested.
The device sends five ping packets by default. You can set a larger value of -c to accurately detect the network status. The device determines the network status based on the number of ping packets returned.
Fault Description |
Possible Cause |
---|---|
All packets can reach the destination but require a long time. |
The intermediate network is unstable. QoS is deployed on the gateway, which lowers the forwarding speed. |
No packet can reach the destination. |
Services on the network are interrupted due to device or cable faults. The firewall on the intermediate network discards ICMP packets. A loop occurs on the network and packets are discarded when the TTL value is reduced to 1. Packets are delayed due to network congestion. |
Some packets cannot reach the destination. |
Some ping packets are discarded on the unstable network. Load balancing is configured on the intermediate network and some ping packets are discarded on one path. Packet flooding attacks. |
Introduction to the Tracert Command
The Ping command checks whether the destination host is reachable and the Tracert command tracks the gateways that packets pass through from the source host to the destination host. This helps check network connectivity and locate network faults. The tracert process is as follows:
- The source host sends a UDP packet with TTL 1.
- The first hop sends back an error ICMP packet, indicating that the packet cannot be sent due to TTL timeout.
- The source host then sends a packet with TTL 2.
- The second hop drops the packet and sends an ICMP TTL-expired packet.
This process proceeds until the packet reaches the destination host. The source host obtains the path to the destination host based on the source IP addresses of TTL-expired packets.
Tracert Command Format
Command Reference provides detailed description of command parameters and usage. Here lists only some commonly used parameters and their descriptions.
tracert [ -a source-ip-address | -f first-ttl | -m max-ttl | -q nqueries | -w timeout ] *host
- -a: specifies the source address. If this parameter is not specified, the IP address of the outbound interface is used as the source IP address of outgoing packets.
- -f: specifies the initial TTL. If the number of hops is smaller than the initial TTL, the source host receives no TTL-expired packet. If a maximum TTL is set, the initial TTL must be smaller than the maximum TTL.
- -m: specifies the maximum TTL. The maximum TTL is usually set to the number of hops through which a Tracert packet passes. If an initial TTL is set, the maximum TTL must be larger than the initial TTL.
- -q: specifies the number of UDP packets sent each time. You can increase this value to ensure that UDP packets can reach the destination host.
- -w: sets the timeout interval of Response messages. If a gateway sends a message indicating TTL timeout, " * " is displayed. You are advised to increase the timeout interval when the network is unstable and the transmission speed is low.
- host: indicates an IP address or a domain name. If it is a domain name, the device performs DNS resolution and displays the resolved IP address.
The tracert function varies with the operating system of a PC. The Windows operating system is used as an example for illustration.
tracert [ -d ] [ -h maximum_hops ] [ -j host-list ] [ -w timeout ] ip-address
- -d: indicates that the host name is not resolved.
- -h: specifies the maximum TTL.
- -j: specifies the loose source address routing list.
- -w: sets the timeout interval of UDP packets, in milliseconds.
Description of the Tracert Command Output
<AC> tracert 10.135.18.118 traceroute to 10.135.18.118(10.135.18.118), max hops: 30 ,packet length: 40,press CTRL_C to break 1 192.168.200.100 10 ms 2 ms 2 ms 2 * * * 3 10.135.18.118 10 ms 1 ms 2 ms
Information displayed in a line includes the number, IP address where the packet reaches, and three response time. * * * is displayed in the second line, indicating that the ping and tracert operations are not supported on this node.
The Ping command can only determine whether the destination is reachable, whereas the Tracert command can detect potential loops on a network. If you track an address and the same address is displayed multiple times, a route loop occurs.