1.\" $NetBSD: ping.8,v 1.47 2006/03/21 22:54:46 pavel Exp $ 2.\" 3.\" Copyright (c) 1985, 1991, 1993 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 31.\" 32.Dd March 21, 2006 33.Dt PING 8 34.Os 35.Sh NAME 36.Nm ping 37.Nd send 38.Tn ICMP ECHO_REQUEST 39packets to network hosts 40.Sh SYNOPSIS 41.Nm 42.Bk -words 43.Op Fl adDfLnoPqQrRv 44.Ek 45.Bk -words 46.Op Fl c Ar count 47.Ek 48.Bk -words 49.Op Fl E Ar policy 50.Ek 51.Bk -words 52.Op Fl g Ar gateway 53.Ek 54.Bk -words 55.Op Fl h Ar host 56.Ek 57.Bk -words 58.Op Fl i Ar interval 59.Ek 60.Bk -words 61.Op Fl I Ar srcaddr 62.Ek 63.Bk -words 64.Op Fl l Ar preload 65.Ek 66.Bk -words 67.Op Fl p Ar pattern 68.Ek 69.Bk -words 70.Op Fl s Ar packetsize 71.Ek 72.Bk -words 73.Op Fl t Ar tos 74.Ek 75.Bk -words 76.Op Fl T Ar ttl 77.Ek 78.Bk -words 79.Op Fl w Ar deadline 80.Ek 81.Ar host 82.Sh DESCRIPTION 83.Nm 84uses the 85.Tn ICMP 86protocol's mandatory 87.Tn ECHO_REQUEST 88datagram to elicit an 89.Tn ICMP ECHO_RESPONSE 90from a host or gateway. 91.Tn ECHO_REQUEST 92datagrams (``pings'') have an IP and 93.Tn ICMP 94header, 95followed by a 96.Dq struct timeval 97and then an arbitrary number of ``pad'' bytes used to fill out the 98packet. 99The options are as follows: 100.Bl -tag -width Ds 101.It Fl a 102Emit an audible beep (by sending an ascii BEL character to the 103standard error output) after each non-duplicate response is received. 104This is disabled for flood pings as it would probably cause temporary 105insanity. 106.It Fl c Ar count 107Stop after sending (and waiting the specified delay to receive) 108.Ar count 109.Tn ECHO_RESPONSE 110packets. 111.It Fl d 112Set the 113.Dv SO_DEBUG 114option on the socket being used. 115.It Fl D 116Set the 117.Dv Don't Fragment 118bit in the IP header. 119This can be used to determine the path MTU. 120.It Fl E Ar policy 121Use IPsec policy specification string 122.Ar policy 123for packets. 124For the format of specification string, please refer 125.Xr ipsec_set_policy 3 . 126Please note that this option is same as 127.Fl P 128in KAME/FreeBSD and KAME/BSDI 129(as 130.Fl P 131was already occupied in 132.Nx ) . 133.It Fl f 134Flood ping. 135Outputs packets as fast as they come back or one hundred times per second, 136whichever is more. 137For every 138.Tn ECHO_REQUEST 139sent a period ``.'' is printed, while for every 140.Tn ECHO_REPLY 141received a backspace is printed. 142This provides a rapid display of how many packets are being dropped. 143Only the super-user may use this option. 144.Bf -emphasis 145This can be very hard on a network and should be used with caution. 146.Ef 147.It Fl g Ar gateway 148Use Loose Source Routing to send the ECHO_REQUEST packets via 149.Ar gateway . 150.It Fl i Ar interval 151Wait 152.Ar interval 153seconds 154.Em between sending each packet . 155The default is to wait for one second between each packet, 156except when the -f option is used the wait interval is 0.01 seconds. 157.It Fl I Ar srcaddr 158Set the source IP address to 159.Ar srcaddr 160which can be a hostname or an IP number. 161For multicast datagrams, it also specifies the outgoing interface. 162.It Fl h Ar host 163is an alternate way of specifying the target host instead of as the 164last argument. 165.It Fl l Ar preload 166If 167.Ar preload 168is specified, 169.Nm 170sends that many packets as fast as possible before falling into its normal 171mode of behavior. 172Only the super-user may use this option. 173.It Fl L 174Disable loopback when sending to multicast destinations, 175so the transmitting host doesn't see the ICMP requests. 176.It Fl n 177Numeric output only. 178No attempt will be made to look up symbolic names for host addresses. 179.It Fl o 180Exit successfully after receiving one reply packet. 181.It Fl p Ar pattern 182You may specify up to 16 ``pad'' bytes to fill out the packet you send. 183This is useful for diagnosing data-dependent problems in a network. 184For example, 185.Dq Li \-p ff 186will cause the sent packet to be filled with all 187ones. 188.It Fl P 189Use a pseudo-random sequence for the data instead of the default, 190fixed sequence of incrementing 8-bit integers. 191This is useful to foil compression on PPP and other links. 192.It Fl q 193Quiet output. 194Nothing is displayed except the summary lines at startup time and 195when finished. 196.It Fl Q 197Do not display responses such as Network Unreachable ICMP messages 198concerning the ECHO_REQUESTs sent. 199.It Fl r 200Bypass the normal routing tables and send directly to a host on an attached 201network. 202If the host is not on a directly-attached network, an error is returned. 203This option can be used to ping a local host through an interface 204that has no route through it (e.g., after the interface was dropped by 205.Xr routed 8 ) . 206.It Fl R 207Record Route. 208Includes the 209.Tn RECORD_ROUTE 210option in the 211.Tn ECHO_REQUEST 212packet and displays the route buffer on returned packets. 213This should show the path to the target host and back, which is 214especially useful in the case of asymmetric routing. 215Note that the IP header is only large enough for nine such addresses, 216and only seven when using the 217.Fl g 218option. 219This is why it was necessary to invent 220.Xr traceroute 8 . 221Many hosts ignore or discard this option. 222.It Fl s Ar packetsize 223Specifies the number of data bytes to be sent. 224The default is 56, which translates into 64 225.Tn ICMP 226data bytes when combined 227with the 8 bytes of 228.Tn ICMP 229header data. 230The maximum allowed value is 65467 bytes. 231.It Fl T Ar ttl 232Use the specified time-to-live. 233.It Fl t Ar tos 234Use the specified hexadecimal type of service. 235.It Fl v 236Verbose output. 237.Tn ICMP 238packets other than 239.Tn ECHO_RESPONSE 240that are received are listed. 241.It Fl w Ar deadline 242Specifies a timeout, in seconds, before ping exits regardless of 243how many packets have been sent or received. 244.El 245.Pp 246When using 247.Nm 248for fault isolation, it should first be run on the local host, to verify 249that the local network interface is up and running. 250Then, hosts and gateways further and further away should be ``pinged''. 251.Pp 252Round-trip times and packet loss statistics are computed. 253If duplicate packets are received, they are not included in the packet 254loss calculation, although the round trip time of these packets is used 255in calculating the minimum/average/maximum round-trip time numbers. 256.Pp 257When the specified number of packets have been sent (and received) or 258if the program is terminated with a 259.Dv SIGINT , 260a brief summary is displayed. 261The summary information can be displayed while 262.Nm 263is running by sending it a 264.Dv SIGINFO 265signal (see the 266.Dq status 267argument for 268.Xr stty 1 269for more information). 270.Pp 271.Nm 272continually sends one datagram per second, and prints one line of 273output for every ECHO_RESPONSE returned. 274On a trusted system with IP 275Security Options enabled, if the network idiom is not MONO, 276.Nm 277also prints a second line containing the hexadecimal representation 278of the IP security option in the ECHO_RESPONSE. 279If the 280.Fl c 281count option is given, only that number of requests is sent. 282No output is produced if there is no response. 283Round-trip times and packet loss statistics are computed. 284If duplicate packets are received, 285they are not included in the packet loss calculation, 286although the round trip time of these packets is used in calculating 287the minimum/average/maximum round-trip time numbers. 288When the specified number of packets have been sent (and received) or if 289the program is terminated with an interrupt (SIGINT), a brief 290summary is displayed. 291When not using the 292.Fl f 293(flood) option, the first interrupt, usually generated by control-C or DEL, 294causes 295.Nm 296to wait for its outstanding requests to return. 297It will wait no longer than the longest round trip time 298encountered by previous, successful pings. 299The second interrupt stops ping immediately. 300.Pp 301This program is intended for use in network testing, measurement and 302management. 303Because of the load it can impose on the network, it is unwise to use 304.Nm 305during normal operations or from automated scripts. 306.Sh ICMP PACKET DETAILS 307An IP header without options is 20 bytes. 308An 309.Tn ICMP 310.Tn ECHO_REQUEST 311packet contains an additional 8 bytes worth of 312.Tn ICMP 313header followed by an arbitrary amount of data. 314When a 315.Ar packetsize 316is given, this indicated the size of this extra piece of data (the 317default is 56). 318Thus the amount of data received inside of an IP packet of type 319.Tn ICMP 320.Tn ECHO_REPLY 321will always be 8 bytes more than the requested data space (the 322.Tn ICMP 323header). 324.Pp 325If the data space is at least eight bytes large, 326.Nm 327uses the first eight bytes of this space to include a timestamp to compute 328round trip times. 329If less than eight bytes of pad are specified, 330no round trip times are given. 331.Sh DUPLICATE AND DAMAGED PACKETS 332.Nm 333will report duplicate and damaged packets. 334Duplicate packets should never occur, and seem to be caused by 335inappropriate link-level retransmissions. 336Duplicates may occur in many situations and are rarely (if ever) a 337good sign, although the presence of low levels of duplicates may not 338always be cause for alarm. 339.Pp 340Damaged packets are obviously serious cause for alarm and often 341indicate broken hardware somewhere in the 342.Nm 343packet's path (in the network or in the hosts). 344.Sh TRYING DIFFERENT DATA PATTERNS 345The (inter)network layer should never treat packets differently depending 346on the data contained in the data portion. 347Unfortunately, data-dependent problems have been known to sneak into 348networks and remain undetected for long periods of time. 349In many cases the particular pattern that will have problems is something 350that doesn't have sufficient ``transitions'', such as all ones or all 351zeros, or a pattern right at the edge, such as almost all zeros. 352It isn't necessarily enough to specify a data pattern of all zeros (for 353example) on the command line because the pattern that is of interest is 354at the data link level, and the relationship between what you type and 355what the controllers transmit can be complicated. 356.Pp 357This means that if you have a data-dependent problem you will probably 358have to do a lot of testing to find it. 359If you are lucky, you may manage to find a file that either can't be sent 360across your network or that takes much longer to transfer than other 361similar length files. 362You can then examine this file for repeated patterns that you can test 363using the 364.Fl p 365option of 366.Nm . 367.Sh TTL DETAILS 368The 369.Tn TTL 370value of an IP packet represents the maximum number of IP routers 371that the packet can go through before being thrown away. 372In current practice you can expect each router in the Internet to decrement 373the 374.Tn TTL 375field by exactly one. 376.Pp 377The 378.Tn TCP/IP 379specification states that the 380.Tn TTL 381field for 382.Tn TCP 383packets should 384be set to 60, but many systems use smaller values 385.Po 386.Bx 4.3 387uses 30, 388.Bx 4.2 389used 15 390.Pc . 391.Pp 392The maximum possible value of this field is 255, and most 393.Ux 394systems set the 395.Tn TTL 396field of 397.Tn ICMP ECHO_REQUEST 398packets to 255. 399This is why you will find you can ``ping'' some hosts, but not reach them 400with 401.Xr telnet 1 402or 403.Xr ftp 1 . 404.Pp 405In normal operation ping prints the ttl value from the packet it receives. 406When a remote system receives a ping packet, it can do one of three things 407with the 408.Tn TTL 409field in its response: 410.Bl -bullet 411.It 412Not change it; this is what Berkeley 413.Ux 414systems did before the 415.Bx 4.3 tahoe 416release. 417In this case the 418.Tn TTL 419value in the received packet will be 255 minus the 420number of routers in the round-trip path. 421.It 422Set it to 255; this is what current Berkeley 423.Ux 424systems do. 425In this case the 426.Tn TTL 427value in the received packet will be 255 minus the 428number of routers in the path 429.Em from 430the remote system 431.Em to 432the 433.Nm Ns Em ing 434host. 435.It 436Set it to some other value. 437Some machines use the same value for 438.Tn ICMP 439packets that they use for 440.Tn TCP 441packets, for example either 30 or 60. 442Others may use completely wild values. 443.El 444.Sh EXIT STATUS 445.Nm 446returns 0 on success (the host is alive), 447and non-zero if the arguments are incorrect or the host is not responding. 448.Sh SEE ALSO 449.Xr netstat 1 , 450.Xr icmp 4 , 451.Xr inet 4 , 452.Xr ip 4 , 453.Xr ifconfig 8 , 454.Xr routed 8 , 455.Xr spray 8 , 456.Xr traceroute 8 457.Sh HISTORY 458The 459.Nm 460command appeared in 461.Bx 4.3 . 462IPsec support was added by WIDE/KAME project. 463.Sh BUGS 464Flood pinging is not recommended in general, and flood pinging a broadcast 465or multicast address should only be done under very controlled conditions. 466.Pp 467The 468.Nm 469program has evolved differently under different operating systems, 470and in some cases the same flag performs a different function 471under different operating systems. 472The 473.Fl t 474flag conflicts with 475.Fx . 476The 477.Fl a , c , i , I , 478.Fl l , p , P , s , 479and 480.Fl t 481flags conflict with 482.Sy Solaris . 483.Pp 484Some hosts and gateways ignore the 485.Tn RECORD_ROUTE 486option. 487.Pp 488The maximum IP header length is too small for options like 489.Tn RECORD_ROUTE 490to 491be completely useful. 492There's not much that that can be done about this, however. 493