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