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