Ping | |
Author: | Mike Muuss |
Developer: | Various open-source and commercial developers |
Platform: | Cross-platform |
Genre: | Command |
License: | Public-domain, BSD, GPL, MIT |
ping
is a computer network administration software utility used to test the reachability of a host on an Internet Protocol (IP) network. It is available for virtually all operating systems that have networking capability, including most embedded network administration software.
Ping measures the round-trip time for messages sent from the originating host to a destination computer that are echoed back to the source. The name comes from active sonar terminology that sends a pulse of sound and listens for the echo to detect objects under water.
Ping operates by means of Internet Control Message Protocol (ICMP) packets. Pinging involves sending an ICMP echo request to the target host and waiting for an ICMP echo reply. The program reports errors, packet loss, and a statistical summary of the results, typically including the minimum, maximum, the mean round-trip times, and standard deviation of the mean.
The command-line options of the ping utility and its output vary between the numerous implementations. Options may include the size of the payload, count of tests, limits for the number of network hops (TTL) that probes traverse, interval between the requests and time to wait for a response. Many systems provide a companion utility ping6, for testing on Internet Protocol version 6 (IPv6) networks, which implement ICMPv6.
The ping utility was written by Mike Muuss in December 1983 during his employment at the Ballistic Research Laboratory, now the US Army Research Laboratory. A remark by David Mills on using ICMP echo packets for IP network diagnosis and measurements prompted Muuss to create the utility to troubleshoot network problems. The author named it after the sound that sonar makes, since its methodology is analogous to sonar's echolocation.[1] [2] The backronym Packet InterNet Groper for PING has been used for over 30 years, and although Muuss says that from his point of view PING was not intended as an acronym, he has acknowledged Mills' expansion of the name.[3] The first released version was public domain software; all subsequent versions have been licensed under the BSD license. Ping was first included in 4.3BSD.[4] The FreeDOS version was developed by Erick Engelke and is licensed under the GPL.[5] Tim Crawford developed the ReactOS version. It is licensed under the MIT License.[6]
RFC 1122 prescribes that any host must process ICMP echo requests and issue echo replies in return.[7]
The following is the output of running ping on Linux for sending five probes (1-second interval by default, configurable via -i option) to the target host www.example.com:
PING www.example.com (93.184.216.34): 56 data bytes64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=11.632 ms64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.726 ms64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=10.683 ms64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=9.674 ms64 bytes from 93.184.216.34: icmp_seq=4 ttl=56 time=11.127 ms
--- www.example.com ping statistics ---5 packets transmitted, 5 packets received, 0.0% packet lossround-trip min/avg/max/stddev = 9.674/10.968/11.726/0.748 ms
The output lists each probe message and the results obtained. Finally, it lists the statistics of the entire test. In this example, the shortest round trip time was 9.674 ms, the average was 10.968 ms, and the maximum value was 11.726 ms. The measurement had a standard deviation of 0.748 ms.
In cases of no response from the target host, most implementations display either nothing or periodically print notifications about timing out. Possible ping results indicating a problem include the following:
In case of error, the target host or an intermediate router sends back an ICMP error message, for example host unreachable or TTL exceeded in transit. In addition, these messages include the first eight bytes of the original message (in this case header of the ICMP echo request, including the quench value), so the ping utility can match responses to originating queries.[8]
Bits 0 - 7 | Bits 8 - 15 | Bits 16 - 23 | Bits 24 - 31 | ||
---|---|---|---|---|---|
Header (20 bytes) | Version/IHL | Type of service (ToS) | Length | ||
Identification | flags and offset | ||||
Time to live (TTL) | Protocol | Header checksum | |||
Source IP address | |||||
Destination IP address | |||||
ICMP header (8 bytes) | Type of message | Code | Checksum | ||
Header data | |||||
ICMP payload (optional) | Payload data |
Bits 0 - 3 | Bits 4 - 7 | Bits 8 - 11 | Bits 12 - 15 | Bits 16 - 23 | Bits 24 - 31 | ||
---|---|---|---|---|---|---|---|
Header (40 bytes) | Version | Traffic class | Flow label | ||||
Payload length | Next header | Hop limit | |||||
Source address (128 bits) | |||||||
Destination address (128 bits) | |||||||
ICMP6 header (8 bytes) | Type of message | Code | Checksum | ||||
Header data | |||||||
ICMP6 payload (optional) | Payload data |
The echo request (ping) is an ICMP/ICMP6 message.
00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Type = 8(IPv4, ICMP) 128(IPv6,ICMP6) | Code = 0 | Checksum | ||||||||||||||||||||||||||||||
Identifier | Sequence Number | |||||||||||||||||||||||||||||||
Payload |
The Identifier and Sequence Number can be used by the client to match the reply with the request that caused the reply. In practice, most Linux systems use a unique identifier for every ping process, and sequence number is an increasing number within that process. Windows uses a fixed identifier, which varies between Windows versions, and a sequence number that is only reset at boot time.
The echo reply is an ICMP message generated in response to an echo request; it is mandatory for all hosts and must include the exact payload received in the request.
00 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Type = 0(IPv4,ICMP) 129(IPv6,ICMP6) | Code = 0 | Checksum | ||||||||||||||||||||||||||||||
Identifier | Sequence Number | |||||||||||||||||||||||||||||||
Payload |
The payload of the packet is generally filled with ASCII characters, as the output of the tcpdump utility shows in the last 32 bytes of the following example (after the eight-byte ICMP header starting with):
The payload may also include a magic packet for the Wake-on-LAN protocol, but the minimum payload, in that case, is longer than shown. The Echo Request typically does not receive any reply if the host was sleeping in hibernation state, but the host still wakes up from sleep state if its interface is configured to accept wakeup requests. If the host is already active and configured to allow replies to incoming ICMP Echo Request packets, the returned reply should include the same payload. This may be used to detect that the remote host was effectively woken up, by repeating a new request after some delay to allow the host to resume its network services. If the host was just sleeping in low power active state, a single request wakes up that host just enough to allow its Echo Reply service to reply instantly if that service was enabled. The host does not need to wake up all devices completely and may return to low-power mode after a short delay. Such configuration may be used to avoid a host to enter in hibernation state, with much longer wake-up delay, after some time passed in low power active mode.
To conduct a denial-of-service attack, an attacker may send ping requests as fast as possible, possibly overwhelming the victim with ICMP echo requests. This technique is called a ping flood.[12]
Ping requests to multiple addresses, ping sweeps, may be used to obtain a list of all hosts on a network.