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