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