xref: /openbsd/sbin/ping/ping.8 (revision 76d0caae)
1.\"	$OpenBSD: ping.8,v 1.65 2021/02/21 17:18:01 jmc Exp $
2.\"	$NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $
3.\"
4.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5.\" All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the project nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.\" Copyright (c) 1985, 1991, 1993
32.\"	The Regents of the University of California.  All rights reserved.
33.\"
34.\" Redistribution and use in source and binary forms, with or without
35.\" modification, are permitted provided that the following conditions
36.\" are met:
37.\" 1. Redistributions of source code must retain the above copyright
38.\"    notice, this list of conditions and the following disclaimer.
39.\" 2. Redistributions in binary form must reproduce the above copyright
40.\"    notice, this list of conditions and the following disclaimer in the
41.\"    documentation and/or other materials provided with the distribution.
42.\" 3. Neither the name of the University nor the names of its contributors
43.\"    may be used to endorse or promote products derived from this software
44.\"    without specific prior written permission.
45.\"
46.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56.\" SUCH DAMAGE.
57.\"
58.\"     @(#)ping.8	8.2 (Berkeley) 12/11/93
59.\"
60.Dd $Mdocdate: February 21 2021 $
61.Dt PING 8
62.Os
63.Sh NAME
64.Nm ping ,
65.Nm ping6
66.Nd send ICMP ECHO_REQUEST packets to network hosts
67.Sh SYNOPSIS
68.Nm ping
69.Op Fl DdEefgHLnqRv
70.Op Fl c Ar count
71.Op Fl I Ar sourceaddr
72.Op Fl i Ar interval
73.Op Fl l Ar preload
74.Op Fl p Ar pattern
75.Op Fl s Ar packetsize
76.Op Fl T Ar toskeyword
77.Op Fl t Ar ttl
78.Op Fl V Ar rtable
79.Op Fl w Ar maxwait
80.Ar host
81.Nm ping6
82.Op Fl DdEefgHLmnqv
83.Op Fl c Ar count
84.Op Fl h Ar hoplimit
85.Op Fl I Ar sourceaddr
86.Op Fl i Ar interval
87.Op Fl l Ar preload
88.Op Fl p Ar pattern
89.Op Fl s Ar packetsize
90.Op Fl T Ar toskeyword
91.Op Fl V Ar rtable
92.Op Fl w Ar maxwait
93.Ar host
94.Sh DESCRIPTION
95.Nm
96uses the ICMP protocol's mandatory
97.Dv ECHO_REQUEST
98datagram to elicit an ICMP
99.Dv ECHO_REPLY
100from a host or gateway.
101These datagrams
102.Pq pings
103have an IP and ICMP header,
104followed by a
105.Qq struct timeval
106and then an arbitrary number of pad bytes used to fill out the packet.
107.Pp
108The options are as follows:
109.Bl -tag -width Ds
110.It Fl c Ar count
111Stop sending after
112.Ar count
113.Dv ECHO_REQUEST
114packets have been sent.
115If
116.Ar count
117is 0, send an unlimited number of packets.
118.It Fl D
119Don't fragment IP packets.
120.It Fl d
121Set the
122.Dv SO_DEBUG
123option on the socket being used.
124This option has no effect on
125.Ox .
126.It Fl E
127Emit an audible beep (by sending an ASCII BEL character to the
128standard error output) when no packet is received before the next
129packet is transmitted.
130To cater for round-trip times that are longer than the interval between
131transmissions, further missing packets cause a bell only if the maximum
132number of unreceived packets has increased.
133This option is disabled for flood pings.
134.It Fl e
135Emit an audible beep (by sending an ASCII BEL character to the
136standard error output) after each non-duplicate response is received.
137This option is disabled for flood pings.
138.It Fl f
139Flood ping.
140Outputs packets as fast as they come back or one hundred times per second,
141whichever is more.
142For every
143.Dv ECHO_REQUEST
144sent, a period
145.Sq \&.
146is printed, while for every
147.Dv ECHO_REPLY
148received a backspace is printed.
149This provides a rapid display of how many packets are being dropped.
150Only the superuser may use this option.
151.Bf -emphasis
152This can be very hard on a network and should be used with caution.
153.Ef
154.It Fl g
155Provides a visual display of packets received and lost.
156For every
157.Dv ECHO_REPLY
158received, an exclamation mark
159.Sq \&!
160is printed, while for every missed packet a period
161.Sq \&.
162is printed.
163Duplicate and truncated replies are indicated with
164.Sq D
165and
166.Sq T
167respectively.
168.It Fl H
169Try reverse lookups for addresses.
170.It Fl h Ar hoplimit
171.Pq IPv6 only
172Set the hoplimit.
173.It Fl I Ar sourceaddr
174Set the source address to transmit from, which is useful on machines
175with multiple interfaces.
176For unicast and multicast pings.
177.It Fl i Ar interval
178Send one packet every
179.Ar interval
180seconds.
181The default is one second.
182The
183.Ar interval
184may contain a fractional portion.
185Only the superuser may specify a value less than one second.
186This option is incompatible with the
187.Fl f
188option.
189.It Fl L
190Disable the loopback, so the transmitting host doesn't see the ICMP
191requests.
192For multicast pings.
193.It Fl l Ar preload
194Send
195.Ar preload
196packets as fast as possible before reverting to normal behavior.
197Only root may set a preload value.
198.It Fl m
199.Pq IPv6 only
200Do not fragment unicast packets to fit the minimum IPv6 MTU.
201If specified twice,
202do this for multicast packets as well.
203.It Fl n
204Numeric output only.
205No attempt will be made to look up symbolic names from addresses in the reply.
206.It Fl p Ar pattern
207Specify up to 16 pad bytes to fill out the packet sent.
208This is useful for diagnosing data-dependent problems in a network.
209For example,
210.Qq -p ff
211causes the sent packet to be filled with all ones.
212.It Fl q
213Quiet output.
214Nothing is displayed except the summary lines at startup time and
215when finished.
216.It Fl R
217.Pq IPv4 only
218Record route.
219Includes the
220.Dv RECORD_ROUTE
221option in the
222.Dv ECHO_REQUEST
223packet and displays
224the route buffer on returned packets.
225Note that the IP header is only large enough for nine such routes.
226If more routes come back than should, such as due to an illegal spoofed
227packet,
228.Nm
229will print the route list and then truncate it at the correct spot.
230Many hosts ignore or discard this option.
231.It Fl s Ar packetsize
232Specify the number of data bytes to be sent.
233The default is 56,
234which translates into 64 ICMP data bytes
235when combined with the 8 bytes of ICMP header data.
236The maximum packet size is 65467 for IPv4 and 65527 for IPv6.
237.It Fl T Ar toskeyword
238Change the IPv4 TOS or IPv6 Traffic Class value.
239.Ar toskeyword
240may be one of
241.Cm critical ,
242.Cm inetcontrol ,
243.Cm lowdelay ,
244.Cm netcontrol ,
245.Cm throughput ,
246.Cm reliability ,
247or one of the DiffServ Code Points:
248.Cm ef ,
249.Cm af11 ... af43 ,
250.Cm cs0 ... cs7 ;
251or a number in either hex or decimal.
252.It Fl t Ar ttl
253.Pq IPv4 only
254Use the specified time-to-live.
255.It Fl V Ar rtable
256Set the routing table to be used for outgoing packets.
257.It Fl v
258Verbose output.
259ICMP packets other than
260.Dv ECHO_REPLY
261that are received are listed.
262.It Fl w Ar maxwait
263Specify the maximum number of seconds to wait for responses
264after the last request has been sent.
265The default is 10.
266.El
267.Pp
268When using
269.Nm
270for fault isolation, it should first be run on the local host to verify
271that the local network interface is up and running.
272Then, hosts and gateways further and further away should be
273.Dq pinged .
274.Pp
275Round trip times and packet loss statistics are computed.
276If duplicate packets are received, they are not included in the packet
277loss calculation, although the round trip time of these packets is used
278in calculating the minimum/average/maximum round trip time numbers and
279the standard deviation.
280.Pp
281When the specified number of packets have been
282sent (and received), or if the program is terminated with a
283.Dv SIGINT ,
284a brief summary is displayed.
285The summary information can also be displayed while
286.Nm
287is running by sending it a
288.Dv SIGINFO
289signal (see the
290.Cm status
291argument of
292.Xr stty 1
293for more information).
294.Pp
295This program is intended for use in network testing, measurement and
296management.
297Because of the load it can impose on the network, it is unwise to use
298.Nm
299during normal operations or from automated scripts.
300.Sh ICMP PACKET DETAILS
301An IP header without options is 20 bytes.
302An ICMP
303.Dv ECHO_REQUEST
304packet contains an additional 8 bytes worth of
305ICMP header followed by an arbitrary amount of data.
306When a
307.Ar packetsize
308is given, this indicates the size of this extra piece of data (the
309default is 56).
310Thus the amount of data received inside of an IP packet of type ICMP
311.Dv ECHO_REPLY
312will always be 8 bytes more than the requested data space
313(the ICMP header).
314.Pp
315If the data space is at least 24 bytes,
316.Nm
317uses the first sixteen bytes of this space to include a timestamp which
318it uses in the computation of round trip times.
319The following 8 bytes store a message authentication code.
320If less than 24 bytes of pad are specified, no round trip times are
321given.
322.Sh DUPLICATE AND DAMAGED PACKETS
323.Nm
324will report duplicate and damaged packets.
325Duplicate packets should never occur, and seem to be caused by
326inappropriate link-level retransmissions.
327Duplicates may occur in many situations and are rarely (if ever) a
328good sign, although the presence of low levels of duplicates may not
329always be cause for alarm.
330.Pp
331Damaged packets are obviously serious cause for alarm and often
332indicate broken hardware somewhere in the
333.Nm
334packet's path (in the network or in the hosts).
335.Sh TRYING DIFFERENT DATA PATTERNS
336The (inter)network layer should never treat packets differently depending
337on the data contained in the data portion.
338Unfortunately, data-dependent problems have been known to sneak into
339networks and remain undetected for long periods of time.
340In many cases the particular pattern that will have problems is something
341that doesn't have sufficient
342.Dq transitions ,
343such as all ones or all
344zeros, or a pattern right at the edge, such as almost all zeros.
345It isn't necessarily enough to specify a data pattern of all zeros (for
346example) on the command line because the pattern that is of interest is
347at the data link level, and the relationship between what you type and
348what the controllers transmit can be complicated.
349.Pp
350This means that if you have a data-dependent problem you will probably
351have to do a lot of testing to find it.
352If you are lucky, you may manage to find a file that either can't be sent
353across your network or that takes much longer to transfer than other
354similar length files.
355You can then examine this file for repeated patterns that you can test
356using the
357.Fl p
358option of
359.Nm ping .
360.Sh TTL DETAILS
361The TTL value of an IP packet represents the maximum number of IP routers
362that the packet can go through before being thrown away.
363In current practice you can expect each router in the Internet to decrement
364the TTL field by exactly one.
365.Pp
366The TCP/IP specification states that the TTL field
367for TCP packets should be set to 60,
368but many systems use smaller values
369.Po
370.Bx 4.3
371uses 30,
372.Bx 4.2
373used 15
374.Pc .
375.Pp
376The maximum possible value of this field is 255, and most
377.Ux
378systems set the TTL field of ICMP
379.Dv ECHO_REQUEST
380packets to 255.
381This is why you will find you can
382.Dq ping
383some hosts, but not reach them
384with
385.Xr telnet 1
386or
387.Xr ftp 1 .
388.Pp
389In normal operation,
390.Nm
391prints the TTL value from the packet it receives.
392When a remote system receives a ping packet, it can do one of three things
393with the TTL field in its response:
394.Bl -bullet
395.It
396Not change it; this is what Berkeley
397.Ux
398systems did before the
399.Bx 4.3 Tahoe
400release.
401In this case the TTL value in the received packet will be
402255 minus the number of routers in the round trip path.
403.It
404Set it to 255; this is what current Berkeley
405.Ux
406systems do.
407In this case the TTL value in the received packet will be
408255 minus the number of routers in the path from the remote system
409to the pinging host.
410.It
411Set it to some other value.
412Some machines use the same value for ICMP packets
413that they use for TCP packets, for example either 30 or 60.
414Others may use completely wild values.
415.El
416.Sh EXIT STATUS
417.Nm
418exits 0 if at least one reply is received,
419and >0 if no reply is received or an error occurred.
420.Sh SEE ALSO
421.Xr netstat 1 ,
422.Xr ifconfig 8
423.Sh HISTORY
424The
425.Nm
426command appeared in
427.Bx 4.3 .
428The
429.Nm ping6
430command was originally a separate program
431and first appeared in the WIDE Hydrangea IPv6 protocol stack kit.
432.Sh BUGS
433Many hosts and gateways ignore the
434.Dv RECORD_ROUTE
435option.
436.Pp
437The maximum IP header length is too small for options like
438.Dv RECORD_ROUTE
439to
440be completely useful.
441There's not much that can be done about this, however.
442.Pp
443Flood pinging is not recommended in general, and flood pinging the
444broadcast address should only be done under very controlled conditions.
445