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