xref: /freebsd/sbin/ping/ping.8 (revision 11afcc8f9f96d657b8e6f7547c02c1957331fc96)
1.\" Copyright (c) 1985, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. All advertising materials mentioning features or use of this software
13.\"    must display the following acknowledgement:
14.\"	This product includes software developed by the University of
15.\"	California, Berkeley and its contributors.
16.\" 4. Neither the name of the University nor the names of its contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\"     @(#)ping.8	8.2 (Berkeley) 12/11/93
33.\"	$Id: ping.8,v 1.14 1998/04/01 00:32:18 imp Exp $
34.\"
35.Dd March 1, 1997
36.Dt PING 8
37.Os BSD 4.3
38.Sh NAME
39.Nm ping
40.Nd send
41.Tn ICMP ECHO_REQUEST
42packets to network hosts
43.Sh SYNOPSIS
44.Nm ping
45.Op Fl QRadfnqrv
46.Op Fl c Ar count
47.Op Fl i Ar wait
48.Op Fl l Ar preload
49.Op Fl p Ar pattern
50.Op Fl s Ar packetsize
51.Bo
52.Ar host |
53.Op Fl L
54.Op Fl I Ar interface
55.Op Fl T Ar ttl
56.Ar mcast-group
57.Bc
58.Sh DESCRIPTION
59.Nm Ping
60uses the
61.Tn ICMP
62.No protocol Ap s mandatory
63.Tn ECHO_REQUEST
64datagram to elicit an
65.Tn ICMP ECHO_RESPONSE
66from a host or gateway.
67.Tn ECHO_REQUEST
68datagrams
69.Pq Dq pings
70have an IP and
71.Tn ICMP
72header, followed by a
73.Dq struct timeval
74and then an arbitrary number of
75.Dq pad
76bytes used to fill out the packet.  The options are as follows:
77.Bl -tag -width indent
78.It Fl a
79Audible. Include a bell
80.Pq ASCII 0x07
81character in the output when any packet is received. This option is ignored
82if other format options are present.
83.It Fl c Ar count
84Stop after sending
85.Pq and receiving
86.Ar count
87.Tn ECHO_RESPONSE
88packets.
89.It Fl d
90Set the
91.Dv SO_DEBUG
92option on the socket being used.
93.It Fl f
94Flood ping.
95Outputs packets as fast as they come back or one hundred times per second,
96whichever is more.
97For every
98.Tn ECHO_REQUEST
99sent a period
100.Dq \&.
101is printed, while for every
102.Tn ECHO_REPLY
103received a backspace is printed.
104This provides a rapid display of how many packets are being dropped.
105Only the super-user may use this option.
106.Bf -emphasis
107This can be very hard on a network and should be used with caution.
108.Ef
109.It Fl i Ar wait
110Wait
111.Ar wait
112seconds
113.Em between sending each packet .
114The default is to wait for one second between each packet.
115This option is incompatible with the
116.Fl f
117option.
118.It Fl I Ar interface
119Source multicast packets with the given interface address.
120This flag only applies if the ping destination is a multicast address.
121.It Fl l Ar preload
122If
123.Ar preload
124is specified,
125.Nm
126sends that many packets as fast as possible before falling into its normal
127mode of behavior.
128Only the super-user may use this option.
129.It Fl L
130Suppress loopback of multicast packets.
131This flag only applies if the ping destination is a multicast address.
132.It Fl n
133Numeric output only.
134No attempt will be made to lookup symbolic names for host addresses.
135.It Fl p Ar pattern
136You may specify up to 16
137.Dq pad
138bytes to fill out the packet you send.
139This is useful for diagnosing data-dependent problems in a network.
140For example,
141.Dq Li \-p ff
142will cause the sent packet to be filled with all
143ones.
144.It Fl Q
145Somewhat quiet output.
146.No Don Ap t
147display ICMP error messages that are in response to our query messages.
148Originally, the
149.Fl v
150flag was required to display such errors, but
151.Fl v
152displays all ICMP error messages.  On a busy machine, this output can
153be overbearing.  Without the
154.Fl Q
155flag,
156.Nm
157prints out any ICMP error messages caused by its own ECHO_REQUEST
158messages.
159.It Fl q
160Quiet output.
161Nothing is displayed except the summary lines at startup time and
162when finished.
163.It Fl R
164Record route.
165Includes the
166.Tn RECORD_ROUTE
167option in the
168.Tn ECHO_REQUEST
169packet and displays
170the route buffer on returned packets.
171Note that the IP header is only large enough for nine such routes;
172the
173.Xr traceroute 8
174command is usually better at determining the route packets take to a
175particular destination.
176If more routes come back than should, such as due to an illegal spoofed
177packet, ping will print the route list and then truncate it at the correct
178spot.
179Many hosts ignore or discard the
180.Tn RECORD_ROUTE
181option.
182.It Fl r
183Bypass the normal routing tables and send directly to a host on an attached
184network.
185If the host is not on a directly-attached network, an error is returned.
186This option can be used to ping a local host through an interface
187that has no route through it
188.Po
189e.g., after the interface was dropped by
190.Xr routed 8
191.Pc .
192.It Fl s Ar packetsize
193Specify the number of data bytes to be sent.
194The default is 56, which translates into 64
195.Tn ICMP
196data bytes when combined
197with the 8 bytes of
198.Tn ICMP
199header data.
200.It Fl T Ar ttl
201Set the IP Time To Live for multicasted packets.
202This flag only applies if the ping destination is a multicast address.
203.It Fl v
204Verbose output.
205.Tn ICMP
206packets other than
207.Tn ECHO_RESPONSE
208that are received are listed.
209.El
210.Pp
211When using
212.Nm
213for fault isolation, it should first be run on the local host, to verify
214that the local network interface is up and running.
215Then, hosts and gateways further and further away should be
216.Dq pinged .
217Round-trip times and packet loss statistics are computed.
218If duplicate packets are received, they are not included in the packet
219loss calculation, although the round trip time of these packets is used
220in calculating the round-trip time statistics.
221When the specified number of packets have been sent
222.Pq and received
223or if the program is terminated with a
224.Dv SIGINT ,
225a brief summary is displayed, showing the number of packets sent and
226received, and the minimum, maximum, mean, and standard deviation of
227the round-trip times.
228.Pp
229This program is intended for use in network testing, measurement and
230management.
231Because of the load it can impose on the network, it is unwise to use
232.Nm
233during normal operations or from automated scripts.
234.Sh ICMP PACKET DETAILS
235An IP header without options is 20 bytes.
236An
237.Tn ICMP
238.Tn ECHO_REQUEST
239packet contains an additional 8 bytes worth of
240.Tn ICMP
241header followed by an arbitrary amount of data.
242When a
243.Ar packetsize
244is given, this indicated the size of this extra piece of data
245.Pq the default is 56 .
246Thus the amount of data received inside of an IP packet of type
247.Tn ICMP
248.Tn ECHO_REPLY
249will always be 8 bytes more than the requested data space
250.Pq the Tn ICMP header .
251.Pp
252If the data space is at least eight bytes large,
253.Nm
254uses the first eight bytes of this space to include a timestamp which
255it uses in the computation of round trip times.
256If less than eight bytes of pad are specified, no round trip times are
257given.
258.Sh DUPLICATE AND DAMAGED PACKETS
259.Nm Ping
260will report duplicate and damaged packets.
261Duplicate packets should never occur when pinging a unicast address,
262and seem to be caused by
263inappropriate link-level retransmissions.
264Duplicates may occur in many situations and are rarely
265.Pq if ever
266a good sign, although the presence of low levels of duplicates may not
267always be cause for alarm.
268Duplicates are expected when pinging a broadcast or multicast address,
269since they are not really duplicates but replies from different hosts
270to the same request.
271.Pp
272Damaged packets are obviously serious cause for alarm and often
273indicate broken hardware somewhere in the
274.Nm
275packet's path (in the network or in the hosts).
276.Sh TRYING DIFFERENT DATA PATTERNS
277The
278(inter)network
279layer should never treat packets differently depending on the data
280contained in the data portion.
281Unfortunately, data-dependent problems have been known to sneak into
282networks and remain undetected for long periods of time.
283In many cases the particular pattern that will have problems is something
284that does not have sufficient
285.Dq transitions ,
286such as all ones or all zeros, or a pattern right at the edge, such as
287almost all zeros.
288It is not
289necessarily enough to specify a data pattern of all zeros (for example)
290on the command line because the pattern that is of interest is
291at the data link level, and the relationship between what you type and
292what the controllers transmit can be complicated.
293.Pp
294This means that if you have a data-dependent problem you will probably
295have to do a lot of testing to find it.
296If you are lucky, you may manage to find a file that either
297cannot
298be sent across your network or that takes much longer to transfer than
299other similar length files.
300You can then examine this file for repeated patterns that you can test
301using the
302.Fl p
303option of
304.Nm Ns .
305.Sh TTL DETAILS
306The
307.Tn TTL
308value of an IP packet represents the maximum number of IP routers
309that the packet can go through before being thrown away.
310In current practice you can expect each router in the Internet to decrement
311the
312.Tn TTL
313field by exactly one.
314.Pp
315The
316.Tn TCP/IP
317specification states that the
318.Tn TTL
319field for
320.Tn TCP
321packets should be set to 60, but many systems use smaller values
322.Po
323.Bx 4.3
324uses 30,
325.Bx 4.2
326used 15
327.Pc .
328.Pp
329The maximum possible value of this field is 255, and most
330.Ux
331systems set
332the
333.Tn TTL
334field of
335.Tn ICMP ECHO_REQUEST
336packets to 255.
337This is why you will find you can
338.Dq ping
339some hosts, but not reach them with
340.Xr telnet 1
341or
342.Xr ftp 1 .
343.Pp
344In normal operation
345.Nm
346prints the ttl value from the packet it receives.
347When a remote system receives a ping packet, it can do one of three things
348with the
349.Tn TTL
350field in its response:
351.Bl -bullet
352.It
353Not change it; this is what
354.Bx
355systems did before the
356.Bx 4.3 tahoe
357release.
358In this case the
359.Tn TTL
360value in the received packet will be 255 minus the
361number of routers in the round-trip path.
362.It
363Set it to 255; this is what current
364.Bx
365systems do.
366In this case the
367.Tn TTL
368value in the received packet will be 255 minus the
369number of routers in the path
370.Em from
371the remote system
372.Em to
373the
374.Nm Ns Em ing
375host.
376.It
377Set it to some other value.
378Some machines use the same value for
379.Tn ICMP
380packets that they use for
381.Tn TCP
382packets, for example either 30 or 60.
383Others may use completely wild values.
384.El
385.Sh RETURN VALUES
386The
387.Nm
388command returns an exit status of zero if at least one response was
389heard from the specified
390.Ar host ;
391a status of two if the transmission was successful but no responses
392were received; or another value
393.Pq from Aq Pa sysexits.h
394if an error occurred.
395.Sh SEE ALSO
396.Xr netstat 1 ,
397.Xr ifconfig 8 ,
398.Xr routed 8 ,
399.Xr traceroute 8
400.Sh HISTORY
401The
402.Nm
403command appeared in
404.Bx 4.3 .
405.Sh AUTHORS
406The original
407.Nm
408command was written by
409.An Mike Muuss
410while at the US Army Ballistics
411Research Laboratory.
412.Sh BUGS
413Many Hosts and Gateways ignore the
414.Tn RECORD_ROUTE
415option.
416.Pp
417The maximum IP header length is too small for options like
418.Tn RECORD_ROUTE
419to be completely useful.
420.No There Ap s
421not much that can be done about this, however.
422.Pp
423Flood pinging is not recommended in general, and flood pinging the
424broadcast address should only be done under very controlled conditions.
425.Pp
426The
427.Fl v
428option is not worth much on busy hosts.
429