xref: /freebsd/sbin/ping/ping.8 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
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.10 1997/03/02 20:01:07 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
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 Ds
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 ping
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.
176Many hosts ignore or discard the
177.Tn RECORD_ROUTE
178option.
179.It Fl r
180Bypass the normal routing tables and send directly to a host on an attached
181network.
182If the host is not on a directly-attached network, an error is returned.
183This option can be used to ping a local host through an interface
184that has no route through it
185.Po
186e.g., after the interface was dropped by
187.Xr routed 8
188.Pc .
189.It Fl s Ar packetsize
190Specifies the number of data bytes to be sent.
191The default is 56, which translates into 64
192.Tn ICMP
193data bytes when combined
194with the 8 bytes of
195.Tn ICMP
196header data.
197.It Fl T Ar ttl
198Set the IP Time To Live for multicasted packets.
199This flag only applies if the ping destination is a multicast address.
200.It Fl v
201Verbose output.
202.Tn ICMP
203packets other than
204.Tn ECHO_RESPONSE
205that are received are listed.
206.El
207.Pp
208When using
209.Nm
210for fault isolation, it should first be run on the local host, to verify
211that the local network interface is up and running.
212Then, hosts and gateways further and further away should be
213.Dq pinged .
214Round-trip times and packet loss statistics are computed.
215If duplicate packets are received, they are not included in the packet
216loss calculation, although the round trip time of these packets is used
217in calculating the minimum/average/maximum round-trip time numbers.
218When the specified number of packets have been sent
219.Pq and received
220or if the program is terminated with a
221.Dv SIGINT ,
222a brief summary is displayed.
223.Pp
224This program is intended for use in network testing, measurement and
225management.
226Because of the load it can impose on the network, it is unwise to use
227.Nm
228during normal operations or from automated scripts.
229.Sh ICMP PACKET DETAILS
230An IP header without options is 20 bytes.
231An
232.Tn ICMP
233.Tn ECHO_REQUEST
234packet contains an additional 8 bytes worth of
235.Tn ICMP
236header followed by an arbitrary amount of data.
237When a
238.Ar packetsize
239is given, this indicated the size of this extra piece of data
240.Pq the default is 56 .
241Thus the amount of data received inside of an IP packet of type
242.Tn ICMP
243.Tn ECHO_REPLY
244will always be 8 bytes more than the requested data space
245.Pq the Tn ICMP header .
246.Pp
247If the data space is at least eight bytes large,
248.Nm
249uses the first eight bytes of this space to include a timestamp which
250it uses in the computation of round trip times.
251If less than eight bytes of pad are specified, no round trip times are
252given.
253.Sh DUPLICATE AND DAMAGED PACKETS
254.Nm Ping
255will report duplicate and damaged packets.
256Duplicate packets should never occur when pinging a unicast address,
257and seem to be caused by
258inappropriate link-level retransmissions.
259Duplicates may occur in many situations and are rarely
260.Pq if ever
261a good sign, although the presence of low levels of duplicates may not
262always be cause for alarm.
263Duplicates are expected when pinging a broadcast or multicast address,
264since they are not really duplicates but replies from different hosts
265to the same request.
266.Pp
267Damaged packets are obviously serious cause for alarm and often
268indicate broken hardware somewhere in the
269.Nm ping
270.No packet Ap s path
271.Pq in the network or in the hosts .
272.Sh TRYING DIFFERENT DATA PATTERNS
273The
274.Po
275inter
276.Pc Ns network
277layer should never treat packets differently depending on the data
278contained in the data portion.
279Unfortunately, data-dependent problems have been known to sneak into
280networks and remain undetected for long periods of time.
281In many cases the particular pattern that will have problems is something
282.No that doesn Ap t have sufficient
283.Dq transitions ,
284such as all ones or all zeros, or a pattern right at the edge, such as
285almost all zeros.
286.No It isn Ap t
287necessarily enough to specify a data pattern of all zeros
288.Pq for example
289on the command line because the pattern that is of interest is
290at the data link level, and the relationship between what you type and
291what the controllers transmit can be complicated.
292.Pp
293This means that if you have a data-dependent problem you will probably
294have to do a lot of testing to find it.
295If you are lucky, you may manage to find a file that either
296.No can Ap t
297be sent across your network or that takes much longer to transfer than
298other similar length files.
299You can then examine this file for repeated patterns that you can test
300using the
301.Fl p
302option of
303.Nm Ns .
304.Sh TTL DETAILS
305The
306.Tn TTL
307value of an IP packet represents the maximum number of IP routers
308that the packet can go through before being thrown away.
309In current practice you can expect each router in the Internet to decrement
310the
311.Tn TTL
312field by exactly one.
313.Pp
314The
315.Tn TCP/IP
316specification states that the
317.Tn TTL
318field for
319.Tn TCP
320packets should be set to 60, but many systems use smaller values
321.Pq Bx 4.3 \ uses 30, Bx 4.2 \ used 15 .
322.Pp
323The maximum possible value of this field is 255, and most Unix systems set
324the
325.Tn TTL
326field of
327.Tn ICMP ECHO_REQUEST
328packets to 255.
329This is why you will find you can
330.Dq ping
331some hosts, but not reach them with
332.Xr telnet 1
333or
334.Xr ftp 1 .
335.Pp
336In normal operation ping prints the ttl value from the packet it receives.
337When a remote system receives a ping packet, it can do one of three things
338with the
339.Tn TTL
340field in its response:
341.Bl -bullet
342.It
343Not change it; this is what Berkeley Unix systems did before the
344.Bx 4.3 tahoe
345release.
346In this case the
347.Tn TTL
348value in the received packet will be 255 minus the
349number of routers in the round-trip path.
350.It
351Set it to 255; this is what current Berkeley Unix systems do.
352In this case the
353.Tn TTL
354value in the received packet will be 255 minus the
355number of routers in the path
356.Em from
357the remote system
358.Em to
359the
360.Nm Ns Em ing
361host.
362.It
363Set it to some other value.
364Some machines use the same value for
365.Tn ICMP
366packets that they use for
367.Tn TCP
368packets, for example either 30 or 60.
369Others may use completely wild values.
370.El
371.Sh RETURN VALUES
372The
373.Nm
374command returns an exit status of zero if at least one response was
375heard from the specified
376.Ar host ;
377a status of two if the transmission was successful but no responses
378were received; or another value
379.Pq from Aq Pa sysexits.h
380if an error occurred.
381.Sh SEE ALSO
382.Xr netstat 1 ,
383.Xr ifconfig 8 ,
384.Xr routed 8 ,
385.Xr traceroute 8
386.Sh HISTORY
387The
388.Nm
389command appeared in
390.Bx 4.3 .
391.Sh AUTHORS
392The original
393.Nm
394command was written by Mike Muuss while at the US Army Ballistics
395Research Laboratory.
396.Sh BUGS
397Many Hosts and Gateways ignore the
398.Tn RECORD_ROUTE
399option.
400.Pp
401The maximum IP header length is too small for options like
402.Tn RECORD_ROUTE
403to be completely useful.
404.No There Ap s
405not much that can be done about this, however.
406.Pp
407Flood pinging is not recommended in general, and flood pinging the
408broadcast address should only be done under very controlled conditions.
409.Pp
410The
411.Fl v
412option is not worth much on busy hosts.
413