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