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