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
- Emit an audible beep (by sending an ASCII BEL character to the standard error output) after receiving each non-duplicate response. For the sake of your sanity, this option is disabled if you use the -f option to do a flood ping.
- -c count
- Stop after sending (and receiving) this many ECHO_RESPONSE packets.
- Set the Don't Fragment bit in the IP header. This is meant to determine the path MTU.
- Set the SO_DEBUG option on the socket being used.
- -E policy
- Specify the IPsec policy for packets.
- Do a flood ping: output packets either
as fast as they come back or one hundred times per second,
whichever is faster.
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.
- -g gateway
- Use Loose Source Routing to send the ECHO_REQUEST packets via gateway. The default is to use the routing table.
- -h host
- Alternate way of specifying the target host instead of as the last argument.
- -I ifaddr
- Send multicast datagrams on the network interface specified by the interface's hostname or IP address.
- -i interval
- Wait interval seconds between sending each packet (default is one second). For the -f option, the interval is 0.01 seconds.
- -l preload
- Send this many packets as fast as possible before returning to normal behavior. Only the superuser may use this option.
- Disable loopback when sending to multicast destinations, so the transmitting host doesn't see the ICMP requests.
- Print numeric output only. No attempt is made to look up symbolic names for host addresses.
- Exit successfully after receiving one reply packet.
- Use a pseudo-random sequence for the data instead of the default, fixed sequence of incrementing 8-bit integers. This is useful to foil compression on PPP and other links.
- -p pattern
- Fill out the packet with this many padding bytes (maximum is 16). You should find this useful for diagnosing data-dependent problems in a network. For example, -p ff causes the sent packet to be filled with ones.
- Don't display responses such as Network Unreachable ICMP messages concerning the ECHO_REQUESTs sent.
- Be quiet: display nothing except for the summary lines at startup time and when finished.
- Record the route.
- Bypass the normal routing tables and send directly to a host on an attached network. If the host isn't on a directly attached network, an error is returned. You can use this option to ping a local host through an interface that has no route through it (e.g. after the interface was dropped by routed).
- -s packetsize
- Send this many data bytes. The default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data.
- -T ttl
- Use the specified time-to-live. It represents how many hops the packet can go through before being discarded (when it reaches 0). The default is 255.
- -t tos
- Use the specified hexadecimal type of service.
- Verbosity (default none).
- -w maxwait
- Specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received.
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.
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.
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:
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:
- If nothing is displayed, ping may be having problems resolving the hostname. Try the IP address directly to bypass the resolver.
- If only the first line of the above successful output is displayed, then ping isn't receiving a response from the specified host.
- All other problems and errors result in an obvious message (e.g. No route to host).
ICMP packet details
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.
Duplicate and damaged packets
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).
Trying different data patterns
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:
- Not change it — this is what Berkeley UNIX systems did before the 4.3BSD-Tahoe release. The TTL value in the received packet is 255 minus the number of routers in the round-trip path.
- Set it to 255 — this is what current Berkeley UNIX systems do. The TTL value in the received packet is 255 minus the number of routers in the path from the remote system to the pinging host.
- Set it to some other value — some machines use the same value for ICMP packets that they use for TCP packets; for example, either 30 or 60. Others may use completely wild values.
The ping utility requires the libsocket.so shared library.
- Success (the host is alive).
- An error occurred. The arguments are incorrect or the host isn't responding.