![]() Linux version of ping | |
Original author(s) | Mike Muuss |
---|---|
Developer(s) | Various open-source and commercial developers |
Initial release | 1983Â (1983) |
Platform | Cross-platform |
Type | 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 in a wide range of operating systems â 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.1
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.
Command-line options and terminal output vary by implementation. 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.
âHistory
DOS version of ping
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.1 The author named it after the sound that sonar makes since its methodology is analogous to sonarâs echolocation.12 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.13 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
Any host must process ICMP echo requests and issue echo replies in return.
Invocation example
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-c5www.example.com
PING www.example.com (93.184.216.34): 56 data bytes
64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=11.632 ms
64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.726 ms
64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=10.683 ms
64 bytes from 93.184.216.34: icmp_seq=3 ttl=56 time=9.674 ms
64 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 loss
round-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.
Error indications
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:
- H, !N or !PÂ â host, network or protocol unreachable
- SÂ â source route failed
- FÂ â fragmentation needed
- U or !WÂ â destination network/host unknown
- IÂ â source host is isolated
- AÂ â communication with destination network administratively prohibited
- ZÂ â communication with destination host administratively prohibited
- QÂ â for this ToS the destination network is unreachable
- TÂ â for this ToS the destination host is unreachable
- XÂ â communication administratively prohibited
- VÂ â host precedence violation
- CÂ â precedence cutoff in effect
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.7
Message format
ICMP packet transported with IPv4
An ICMP packet transported with IPv4 looks like this.
Offset | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
0 | 0 | Version(4) | IHL(5) | DSCP(0) | ECN(0) | Total length | |||||||||||||||||||||||||||
4 | 32 | Identification | Flags | Fragment offset | |||||||||||||||||||||||||||||
8 | 64 | Time to live | Protocol(1) | Header checksum | |||||||||||||||||||||||||||||
12 | 96 | Source address | |||||||||||||||||||||||||||||||
16 | 128 | Destination address |
20 | 160 | Type(8) | Code(0) | Checksum | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24 | 192 | Identifier | Sequence number | ||||||||||||||||||||||||||||||
28 | 224 | (Payload) | |||||||||||||||||||||||||||||||
32 | 256 | ||||||||||||||||||||||||||||||||
âź | âź |
Type: 8 bits
Set to 8 to indicate âEcho Requestâ.8
Checksum: 16 bits
Checksum is the 16-bit onesâ complement of the onesâ complement sum of the ICMP packet, starting with the Type field,9 including the Payload. The IP header is not included.
Identifier: 16 bits
Can be used by the client to match the reply with the request that caused the reply.
Sequence number: 16 bits
Can be used by the client to match the reply with the request that caused the reply.
Payload: variable length
Optional. Payload for the different kind of answers; can be an arbitrary length, left to implementation detail.
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 returned as:
20 | 160 | Type(0) | Code(0) | Checksum | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24 | 192 | Identifier | Sequence number | ||||||||||||||||||||||||||||||
28 | 224 | (Payload) | |||||||||||||||||||||||||||||||
32 | 256 | ||||||||||||||||||||||||||||||||
âź | âź |
Type: 8 bits
Set to 0 to indicate âEcho Replyâ.8
Identifier: 16 bits
Copied from the Echo Request and returned.
Sequence number: 16 bits
Copied from the Echo Request and returned.
Payload: variable length
Optional. Payload is copied from the Echo Request and returned.
ICMPv6 packet transported with IPv6
An ICMP packet transported with IPv6 looks like this.
Offset | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
0 | 0 | Version(6) | Traffic class | Flow label | |||||||||||||||||||||||||||||
4 | 32 | Payload length | Next header(58) | Hop limit | |||||||||||||||||||||||||||||
8 | 64 | Source address | |||||||||||||||||||||||||||||||
12 | 96 | ||||||||||||||||||||||||||||||||
16 | 128 | ||||||||||||||||||||||||||||||||
20 | 160 | ||||||||||||||||||||||||||||||||
24 | 192 | Destination address | |||||||||||||||||||||||||||||||
28 | 224 | ||||||||||||||||||||||||||||||||
32 | 256 | ||||||||||||||||||||||||||||||||
36 | 288 |
40 | 320 | Type(128) | Code(0) | Checksum | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
44 | 352 | Identifier | Sequence number | ||||||||||||||||||||||||||||||
48 | 384 | (Payload) | |||||||||||||||||||||||||||||||
52 | 416 | ||||||||||||||||||||||||||||||||
âź | âź |
Type: 8 bits
Set to 128 to indicate âEcho Requestâ.
Identifier: 16 bits
Can be used by the client to match the reply with the request that caused the reply.
Sequence number: 16 bits
Can be used by the client to match the reply with the request that caused the reply.
Checksum: 16 bits
The checksum is calculated from the ICMP message (starting with the Type field), prepended with an IPv6 pseudo-header.10
Payload: variable length
Optional. Payload for the different kind of answers; can be an arbitrary length, left to implementation detail.
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 returned as:
40 | 320 | Type(129) | Code(0) | Checksum | |||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
44 | 352 | Identifier | Sequence number | ||||||||||||||||||||||||||||||
48 | 384 | (Payload) | |||||||||||||||||||||||||||||||
52 | 416 | ||||||||||||||||||||||||||||||||
âź | âź |
Type: 8 bits
Set to 129 to indicate âEcho Replyâ.
Identifier: 16 bits
Copied from the Echo Request and returned.
Sequence number: 16 bits
Copied from the Echo Request and returned.
Payload: variable length
Optional. Payload is copied from the Echo Request and returned.
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 0x0800):
16:24:47.966461IP(tos0x0,ttl128,id15103,offset0,flags[none],
proto:ICMP(1),length:60)192.168.146.22>192.168.144.5:ICMPechorequest,
id1,seq38,length40
0x0000:4500003c3aff000080015c55c0a89216E..<:.....\U....
0x0010:c0a8900508004d350001002661626364......M5...&abcd
0x0020:65666768696a6b6c6d6e6f7071727374efghijklmnopqrst
0x0030:757677616263646566676869 uvwabcdefghi
The payload may include a timestamp indicating the time of transmission and a sequence number, which are not found in this example. This allows ping to compute the round-trip time in a stateless manner without needing to record the time of transmission of each packet.
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.
A packet including IP and ICMP headers must not be greater than the maximum transmission unit of the network, or risk being fragmented.
Security loopholes
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.11
Ping requests to multiple addresses, ping sweeps, may be used to obtain a list of all hosts on a network.
See also
References
Further reading
- Dyson, Peter (1995). Mastering OS/2 Warp. Sybex. ISBNÂ 978-0782116632.
- John Paul Mueller (2007). Windows Administration at the Command Line for Windows Vista, Windows 2003, Windows XP, and Windows 2000. John Wiley & Sons. ISBNÂ 978-0470165799.
- McElhearn, Kirk (2006). The Mac OS X Command Line: Unix Under the Hood. John Wiley & Sons. ISBNÂ 978-0470113851.
External links
Wikibooks has a book on the topic of: Guide to Windows Commands
[ping(1M)](https://docs.oracle.com/cd/E88353_01/html//ping-1m.html)
 â Solaris 11.4 Reference Manual[ping(8)](https://www.freebsd.org/cgi/man.cgi?query=ping&sektion=8)
 â FreeBSD System Managerâs Manual[ping(8)](https://manned.org/ping.8)
 â Linux Programmerâs Manual â Administration and Privileged Commands- ping at Microsoft Docs
Footnotes
-
Mike Muuss. âThe Story of the PING Programâ. U.S. Army Research Laboratory. Archived from the original on 25 October 2019. Retrieved 8 September 2010. My original impetus for writing PING for 4.2a BSD UNIX came from an offhand remark in July 1983 by Dr. Dave Mills ⊠I named it after the sound that a sonar makes, inspired by the whole principle of echo-location ⊠From my point of view PING is not an acronym standing for Packet InterNet Grouper, itâs a sonar analogy. However, Iâve heard second-hand that Dave Mills offered this expansion of the name, so perhaps weâre both right. â© â©2 â©3 â©4
-
Salus, Peter (1994). A Quarter Century of UNIX. Addison-Wesley. ISBNÂ 978-0-201-54777-1. â©
-
Mills, D.L. (December 1983). Internet Delay Experiments. IETF. doi:10.17487/RFC0889. RFC 889. Retrieved 26 November 2019. â©
-
âibiblio.org FreeDOS Package â ping (Networking)â. www.ibiblio.org. â©
-
âGitHub - reactos/reactos: A free Windows-compatible Operating Systemâ. 8 August 2019 â via GitHub. â©
-
âICMP: Internet Control Message Protocolâ. repo.hackerzvoice.net. 13 January 2000. Archived from the original on 4 August 2016. Retrieved 4 December 2014. â©
-
J. Postel (September 1981). INTERNET CONTROL MESSAGE PROTOCOL - DARPA INTERNET PROGRAM PROTOCOL SPECIFICATION. Network Working Group. doi:10.17487/RFC0792. STD 5. RFC 792. Internet Standard 5. Updates RFCÂ 760, 777, IENs 109, 128. Updated by RFCÂ 950, 4884, 6633 and 6918. â© â©2
-
âRFC Sourcebookâs page on ICMPâ. Archived from the original on 6 July 2018. Retrieved 20 December 2010. â©
-
A. Conta; S. Deering (March 2006). M. Gupta (ed.). Internet Control Message Protocol (ICMPv6) for the Internet Protocol Version 6 (IPv6) Specification. Network Working Group. doi:10.17487/RFC4443. STD 89. RFC 4443. Internet Standard 89. Obsoletes RFCÂ 2463. Updates RFCÂ 2780. Updated by RFCÂ 4884. â©
-
âWhat is a Ping Flood | ICMP Flood | DDoS Attack Glossary | Impervaâ. Learning Center. Retrieved 26 July 2021. â©