1.\" $OpenBSD: ping.8,v 1.46 2011/09/17 14:10:05 haesbaert Exp $ 2.\" $NetBSD: ping.8,v 1.10 1995/12/31 04:55:35 ghudson Exp $ 3.\" 4.\" Copyright (c) 1985, 1991, 1993 5.\" The Regents of the University of California. 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 University 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 REGENTS 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 REGENTS 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.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 32.\" 33.Dd $Mdocdate: September 17 2011 $ 34.Dt PING 8 35.Os 36.Sh NAME 37.Nm ping 38.Nd send ICMP ECHO_REQUEST packets to network hosts 39.Sh SYNOPSIS 40.Nm ping 41.Bk -words 42.Op Fl DdEefLnqRrv 43.Op Fl c Ar count 44.Op Fl I Ar ifaddr 45.Op Fl i Ar wait 46.Op Fl l Ar preload 47.Op Fl p Ar pattern 48.Op Fl s Ar packetsize 49.Op Fl T Ar toskeyword 50.Op Fl t Ar ttl 51.Op Fl V Ar rtable 52.Op Fl w Ar maxwait 53.Ar host 54.Ek 55.Sh DESCRIPTION 56.Nm 57uses the ICMP protocol's mandatory 58.Dv ECHO_REQUEST 59datagram to elicit an ICMP 60.Dv ECHO_REPLY 61from a host or gateway. 62.Dv ECHO_REQUEST 63datagrams 64.Pq Dq pings 65have an IP and ICMP header, 66followed by a 67.Dq struct timeval 68and then an arbitrary number of 69.Dq pad 70bytes used to fill out the packet. 71The options are as follows: 72.Bl -tag -width Ds 73.It Fl c Ar count 74Stop sending after 75.Ar count 76.Dv ECHO_REQUEST 77packets have been sent. 78If 79.Ar count 80is 0, send an unlimited number of packets. 81.It Fl D 82Set the 83.Dv Don't Fragment 84bit. 85.It Fl d 86Set the 87.Dv SO_DEBUG 88option on the socket being used. 89.It Fl E 90Emit an audible beep (by sending an ASCII BEL character to the 91standard error output) when no packet is received before the next 92packet is transmitted. 93To cater for round-trip times that are longer than the interval between 94transmissions, further missing packets cause a bell only if the maximum 95number of unreceived packets has increased. 96This option is disabled for flood pings. 97.It Fl e 98Emit an audible beep (by sending an ASCII BEL character to the 99standard error output) after each non-duplicate response is received. 100This option is disabled for flood pings. 101.It Fl f 102Flood ping. 103Outputs packets as fast as they come back or one hundred times per second, 104whichever is more. 105For every 106.Dv ECHO_REQUEST 107sent, a period 108.Sq \&. 109is printed, while for every 110.Dv ECHO_REPLY 111received a backspace is printed. 112This provides a rapid display of how many packets are being dropped. 113Only the superuser may use this option. 114.Bf -emphasis 115This can be very hard on a network and should be used with caution. 116.Ef 117.It Fl I Ar ifaddr 118Specify the interface address to transmit from 119on machines with multiple interfaces. 120For unicast and multicast pings. 121.It Fl i Ar wait 122Wait 123.Ar wait 124seconds between sending each packet. 125The default is to wait for one second between each packet. 126The wait time may be fractional, but only the superuser may specify 127a value less than one second. 128This option is incompatible with the 129.Fl f 130option. 131.It Fl L 132Disable the loopback, so the transmitting host doesn't see the ICMP 133requests. 134For multicast pings. 135.It Fl l Ar preload 136If 137.Ar preload 138is specified, 139.Nm 140sends that many packets as fast as possible before falling into its normal 141mode of behavior. 142Only root may set a preload value. 143.It Fl n 144Numeric output only. 145No attempt will be made to look up symbolic names for host addresses. 146.It Fl p Ar pattern 147You may specify up to 16 148.Dq pad 149bytes to fill out the packet you send. 150This is useful for diagnosing data-dependent problems in a network. 151For example, 152.Dq -p ff 153will cause the sent packet to be filled with all ones. 154.It Fl q 155Quiet output. 156Nothing is displayed except the summary lines at startup time and 157when finished. 158.It Fl R 159Record route. 160Includes the 161.Dv RECORD_ROUTE 162option in the 163.Dv ECHO_REQUEST 164packet and displays 165the route buffer on returned packets. 166Note that the IP header is only large enough for nine such routes. 167If more routes come back than should, such as due to an illegal spoofed 168packet, 169.Nm 170will print the route list and then truncate it at the correct spot. 171Many hosts ignore or discard this option. 172.It Fl r 173Bypass the normal routing tables and send directly to a host on an attached 174network. 175If the host is not on a directly attached network, an error is returned. 176This option can be used to ping a local host through an interface 177that has no route through it. 178.It Fl s Ar packetsize 179Specifies the number of data bytes to be sent. 180The default is 56, 181which translates into 64 ICMP data bytes 182when combined with the 8 bytes of ICMP header data. 183.It Fl T Ar toskeyword 184Change IPv4 TOS value. 185.Ar toskeyword 186may be one of 187.Ar critical , 188.Ar inetcontrol , 189.Ar lowdelay , 190.Ar netcontrol , 191.Ar throughput , 192.Ar reliability , 193or one of the DiffServ Code Points: 194.Ar ef , 195.Ar af11 ... af43 , 196.Ar cs0 ... cs7 ; 197or a number in either hex or decimal. 198.It Fl t Ar ttl 199Use the specified time-to-live. 200.It Fl V Ar rtable 201Set the routing table to be used for outgoing packets. 202The default is 0. 203.It Fl v 204Verbose output. 205ICMP packets other than 206.Dv ECHO_REPLY 207that are received are listed. 208.It Fl w Ar maxwait 209Specifies the maximum number of seconds to wait for responses 210after the last request has been sent. 211The default is 10. 212.El 213.Pp 214When using 215.Nm 216for fault isolation, it should first be run on the local host to verify 217that the local network interface is up and running. 218Then, hosts and gateways further and further away should be 219.Dq pinged . 220.Pp 221Round trip times and packet loss statistics are computed. 222If duplicate packets are received, they are not included in the packet 223loss calculation, although the round trip time of these packets is used 224in calculating the minimum/average/maximum round trip time numbers and 225the standard deviation. 226.Pp 227When the specified number of packets have been 228sent (and received), or if the program is terminated with a 229.Dv SIGINT , 230a brief summary is displayed. 231The summary information can also be displayed while 232.Nm 233is running by sending it a 234.Dv SIGINFO 235signal (see the 236.Cm status 237argument of 238.Xr stty 1 239for more information). 240.Pp 241This program is intended for use in network testing, measurement and 242management. 243Because of the load it can impose on the network, it is unwise to use 244.Nm 245during normal operations or from automated scripts. 246.Pp 247.Nm 248exits 0 if at least one reply is received, 249and \*(Gt0 if no reply is received or an error occurred. 250.Sh ICMP PACKET DETAILS 251An IP header without options is 20 bytes. 252An ICMP 253.Dv ECHO_REQUEST 254packet contains an additional 8 bytes worth of 255ICMP header followed by an arbitrary amount of data. 256When a 257.Ar packetsize 258is given, this indicates the size of this extra piece of data (the 259default is 56). 260Thus the amount of data received inside of an IP packet of type ICMP 261.Dv ECHO_REPLY 262will always be 8 bytes more than the requested data space 263(the ICMP header). 264.Pp 265If the data space is at least eight bytes large, 266.Nm 267uses the first eight bytes of this space to include a timestamp which 268it uses in the computation of round trip times. 269If less than eight bytes of pad are specified, no round trip times are 270given. 271.Sh DUPLICATE AND DAMAGED PACKETS 272.Nm 273will report duplicate and damaged packets. 274Duplicate packets should never occur, and seem to be caused by 275inappropriate link-level retransmissions. 276Duplicates may occur in many situations and are rarely (if ever) a 277good sign, although the presence of low levels of duplicates may not 278always be cause for alarm. 279.Pp 280Damaged packets are obviously serious cause for alarm and often 281indicate broken hardware somewhere in the 282.Nm 283packet's path (in the network or in the hosts). 284.Sh TRYING DIFFERENT DATA PATTERNS 285The (inter)network layer should never treat packets differently depending 286on the data contained in the data portion. 287Unfortunately, data-dependent problems have been known to sneak into 288networks and remain undetected for long periods of time. 289In many cases the particular pattern that will have problems is something 290that doesn't have sufficient 291.Dq transitions , 292such as all ones or all 293zeros, or a pattern right at the edge, such as almost all zeros. 294It isn't necessarily enough to specify a data pattern of all zeros (for 295example) on the command line because the pattern that is of interest is 296at the data link level, and the relationship between what you type and 297what the controllers transmit can be complicated. 298.Pp 299This means that if you have a data-dependent problem you will probably 300have to do a lot of testing to find it. 301If you are lucky, you may manage to find a file that either can't be sent 302across your network or that takes much longer to transfer than other 303similar length files. 304You can then examine this file for repeated patterns that you can test 305using the 306.Fl p 307option of 308.Nm ping . 309.Sh TTL DETAILS 310The TTL value of an IP packet represents the maximum number of IP routers 311that the packet can go through before being thrown away. 312In current practice you can expect each router in the Internet to decrement 313the TTL field by exactly one. 314.Pp 315The TCP/IP specification states that the TTL field 316for TCP packets should be set to 60, 317but many systems use smaller values 318(4.3 BSD uses 30, 4.2 used 15). 319.Pp 320The maximum possible value of this field is 255, and most 321.Ux 322systems set the TTL field of ICMP 323.Dv ECHO_REQUEST 324packets to 255. 325This is why you will find you can 326.Dq ping 327some hosts, but not reach them 328with 329.Xr telnet 1 330or 331.Xr ftp 1 . 332.Pp 333In normal operation, 334.Nm 335prints the TTL value from the packet it receives. 336When a remote system receives a ping packet, it can do one of three things 337with the TTL field in its response: 338.Bl -bullet 339.It 340Not change it; this is what Berkeley 341.Ux 342systems did before the 343.Bx 4.3 tahoe 344release. 345In this case the TTL value in the received packet will be 346255 minus the number of routers in the round trip path. 347.It 348Set it to 255; this is what current Berkeley 349.Ux 350systems do. 351In this case the TTL value in the received packet will be 352255 minus the number of routers in the path from the remote system 353to the pinging host. 354.It 355Set it to some other value. 356Some machines use the same value for ICMP packets 357that they use for TCP packets, for example either 30 or 60. 358Others may use completely wild values. 359.El 360.Sh SEE ALSO 361.Xr netstat 1 , 362.Xr ifconfig 8 , 363.Xr ping6 8 , 364.Xr spray 8 365.Sh HISTORY 366The 367.Nm 368command appeared in 369.Bx 4.3 . 370.Sh BUGS 371Many hosts and gateways ignore the 372.Dv RECORD_ROUTE 373option. 374.Pp 375The maximum IP header length is too small for options like 376.Dv RECORD_ROUTE 377to 378be completely useful. 379There's not much that can be done about this, however. 380.Pp 381Flood pinging is not recommended in general, and flood pinging the 382broadcast address should only be done under very controlled conditions. 383