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