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