Send ICMP ECHO_REQUEST packets to network hosts (UNIX)
ping [-aDdfLnoPQqRrv] [-c count] [-E policy] [-g gateway] [-h host] [-I ifaddr] [-i wait] [-i interval] [-l preload] [-p pattern] [-s packetsize] [-t tos] [-T ttl] [-w maxwait] host
Neutrino
For every ECHO_REQUEST sent, a “.” is printed; for every ECHO_REPLY received, a backspace is printed. This quickly shows how many packets are being dropped.
Only the superuser (root) may use the -f option; it can be very hard on a network — use it with caution. |
The ping utility uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ICMP ECHO_RESPONSE from the given host or gateway. ECHO_REQUEST datagrams, known as pings, have an IP and ICMP header, followed by a timeval structure and then an arbitrary number of padding bytes used to fill out the packet.
This utility needs to have the setuid (“set user ID”) bit set in its permissions. If you use mkefs, mketfs, or mkifs on a Windows host to include this utility in an image, use the perms attribute to specify its permissions explicitly, and the uid and gid attributes to set the ownership correctly. |
When using ping for isolating faults, you should first run it on the local host to verify that the local network interface is up and running. You should then ping hosts and gateways further and further away. Round-trip times and packet-loss statistics are computed. If duplicate packets are received, they aren't included in the packet-loss calculation, although the round-trip time of these packets is used in calculating the minimum/average/maximum round-trip time numbers. When the specified number of packets has been sent (and received), or if you terminate ping with a SIGINT, a brief summary is displayed.
The ping utility is intended for testing, measuring, and managing networks. Because of the load it can impose on the network, you shouldn't use ping during normal operations or from automated scripts. |
You can use the ping utility to determine if you have connectivity to other hosts. Suppose you've configured a point-to-point link (PPP), but you haven't specified a default route. You can type the following to see if you're connected to the other end of the link:
ping isp.com
With success, ping outputs something like this:
PING isp.com (10.0.0.1): 56 data bytes 64 bytes from 10.0.0.1: icmp_seq=0 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=1 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=2 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=3 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=4 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=5 ttl=255 time=0 ms 64 bytes from 10.0.0.1: icmp_seq=6 ttl=255 time=0 ms
This report continues until ping is terminated. To terminate ping, press Ctrl-C. You'll see a report like this:
--- isp.com ping statistics --- 7 packets transmitted, 7 packets received, 0% packet loss round-trip min/avg/max = 0/0/0 ms
The ping utility may fail for different reasons:
An IP header without options is 20 bytes. An ICMP ECHO_REQUEST packet contains an additional 8 bytes worth of ICMP header followed by an arbitrary amount of data. (Specifying a packetsize via option -s determines the size of this extra piece of data; default is 56). Thus the amount of data received inside of an IP packet of type ICMP ECHO_REPLY is always 8 bytes more than the requested data space (the ICMP header).
If the size of the data space is at least 8 bytes, ping uses the first 8 bytes of this space to include a timestamp that it uses in the computation of round-trip times. If less than eight bytes of padding are specified (option -p), no round-trip times are given.
The ping utility reports duplicate and damaged packets.
Although they should never happen, duplicate packets can occur in many situations and seem to be caused by inappropriate link-level retransmissions. While duplicates are rarely (if ever) a good sign, the presence of low levels of duplicates isn't always cause for alarm.
Damaged packets, on the other hand, are serious and often indicate malfunctioning hardware somewhere in the ping packet's path (in the network or in the hosts).
The (inter)network layer should never treat packets according to the data contained in the data portion. Unfortunately, data-dependent problems have been known to sneak into networks and remain undetected for long periods of time. In many cases, the particular pattern that will have problems is something that doesn't have sufficient “transitions,” such as all ones or all zeros, or a pattern right at the edge, such as almost all zeros. It isn't necessarily enough to specify a data pattern of all zeros, for example, on the command line because the pattern of interest is at the data-link level—the relationship between what you type and what the controllers transmit can be complicated.
So if you have a data-dependent problem, you'll probably have to do a lot of testing to find it. If you're lucky, you may manage to find a file that either can't be sent across your network or that takes much longer to transfer than other similar length files. You can then examine this file for repeated patterns that you can test using the -p option.
The TTL value of an IP packet represents the maximum number of IP routers that the packet can go through before being thrown away. In current practice you can expect each router in the Internet to decrement the TTL field by exactly one. The TCP/IP specification states that the TTL field for TCP packets should be set to 60, but many systems use smaller values (4.3 BSD uses 30, 4.2 uses 15).
The maximum possible value of this field is 255, and most UNIX systems (including QNX) set the TTL field of ICMP ECHO_REQUEST packets to 255. Thus you'll find you can “ping” some hosts, but not reach them with telnet or ftp.
In normal operation, ping prints the ttl value from the packet it receives. When a remote system receives a ping packet, it can do one of three things with the TTL field in its response:
The ping utility requires the libsocket.so shared library.