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. Neither the name of the University nor the names of its contributors 13.\" may be used to endorse or promote products derived from this software 14.\" without specific prior written permission. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.\" @(#)ping.8 8.2 (Berkeley) 12/11/93 29.\" $FreeBSD$ 30.\" 31.Dd August 21, 2019 32.Dt PING 8 33.Os 34.Sh NAME 35.Nm ping 36.Nd send 37.Tn ICMP ECHO_REQUEST 38packets to network hosts 39.Sh SYNOPSIS 40.Nm 41.Op Fl AaDdfHnoQqRrv 42.Op Fl c Ar count 43.Op Fl G Ar sweepmaxsize 44.Op Fl g Ar sweepminsize 45.Op Fl h Ar sweepincrsize 46.Op Fl i Ar wait 47.Op Fl l Ar preload 48.Op Fl M Cm mask | time 49.Op Fl m Ar ttl 50.Op Fl P Ar policy 51.Op Fl p Ar pattern 52.Op Fl S Ar src_addr 53.Op Fl s Ar packetsize 54.Op Fl t Ar timeout 55.Op Fl W Ar waittime 56.Op Fl z Ar tos 57.Ar host 58.Nm 59.Op Fl AaDdfHLnoQqRrv 60.Op Fl c Ar count 61.Op Fl I Ar iface 62.Op Fl i Ar wait 63.Op Fl l Ar preload 64.Op Fl M Cm mask | time 65.Op Fl m Ar ttl 66.Op Fl P Ar policy 67.Op Fl p Ar pattern 68.Op Fl S Ar src_addr 69.Op Fl s Ar packetsize 70.Op Fl T Ar ttl 71.Op Fl t Ar timeout 72.Op Fl W Ar waittime 73.Op Fl z Ar tos 74.Ar mcast-group 75.Sh DESCRIPTION 76The 77.Nm 78utility uses the 79.Tn ICMP 80.No protocol Ap s mandatory 81.Tn ECHO_REQUEST 82datagram to elicit an 83.Tn ICMP ECHO_RESPONSE 84from a host or gateway. 85.Tn ECHO_REQUEST 86datagrams 87.Pq Dq pings 88have an IP and 89.Tn ICMP 90header, followed by a 91.Dq struct timeval 92and then an arbitrary number of 93.Dq pad 94bytes used to fill out the packet. 95The options are as follows: 96.Bl -tag -width indent 97.It Fl A 98Audible. 99Output a bell 100.Tn ( ASCII 1010x07) 102character when no packet is received before the next packet 103is transmitted. 104To cater for round-trip times that are longer than the interval 105between transmissions, further missing packets cause a bell only 106if the maximum number of unreceived packets has increased. 107.It Fl a 108Audible. 109Include a bell 110.Tn ( ASCII 1110x07) 112character in the output when any packet is received. 113This option is ignored 114if other format options are present. 115.It Fl c Ar count 116Stop after sending 117(and receiving) 118.Ar count 119.Tn ECHO_RESPONSE 120packets. 121If this option is not specified, 122.Nm 123will operate until interrupted. 124If this option is specified in conjunction with ping sweeps, 125each sweep will consist of 126.Ar count 127packets. 128.It Fl D 129Set the Don't Fragment bit. 130.It Fl d 131Set the 132.Dv SO_DEBUG 133option on the socket being used. 134.It Fl f 135Flood ping. 136Outputs packets as fast as they come back or one hundred times per second, 137whichever is more. 138For every 139.Tn ECHO_REQUEST 140sent a period 141.Dq .\& 142is printed, while for every 143.Tn ECHO_REPLY 144received a backspace is printed. 145This provides a rapid display of how many packets are being dropped. 146Only the super-user may use this option. 147.Bf -emphasis 148This can be very hard on a network and should be used with caution. 149.Ef 150.It Fl G Ar sweepmaxsize 151Specify the maximum size of 152.Tn ICMP 153payload when sending sweeping pings. 154This option is required for ping sweeps. 155.It Fl g Ar sweepminsize 156Specify the size of 157.Tn ICMP 158payload to start with when sending sweeping pings. 159The default value is 0. 160.It Fl H 161Hostname output. 162Try to do a reverse DNS lookup when displaying addresses. 163This is the opposite of 164.Fl n , 165and it is the default behavior. 166.Nm 167utility tries reverse-lookup by default. 168.It Fl h Ar sweepincrsize 169Specify the number of bytes to increment the size of 170.Tn ICMP 171payload after 172each sweep when sending sweeping pings. 173The default value is 1. 174.It Fl I Ar iface 175Source multicast packets with the given interface address. 176This flag only applies if the ping destination is a multicast address. 177.It Fl i Ar wait 178Wait 179.Ar wait 180seconds 181.Em between sending each packet . 182The default is to wait for one second between each packet. 183The wait time may be fractional, but only the super-user may specify 184values less than 1 second. 185This option is incompatible with the 186.Fl f 187option. 188.It Fl L 189Suppress loopback of multicast packets. 190This flag only applies if the ping destination is a multicast address. 191.It Fl l Ar preload 192If 193.Ar preload 194is specified, 195.Nm 196sends that many packets as fast as possible before falling into its normal 197mode of behavior. 198Only the super-user may use this option. 199.It Fl M Cm mask | time 200Use 201.Dv ICMP_MASKREQ 202or 203.Dv ICMP_TSTAMP 204instead of 205.Dv ICMP_ECHO . 206For 207.Cm mask , 208print the netmask of the remote machine. 209Set the 210.Va net.inet.icmp.maskrepl 211MIB variable to enable 212.Dv ICMP_MASKREPLY 213and 214.Va net.inet.icmp.maskfake 215if you want to override the netmask in the response. 216For 217.Cm time , 218print the origination, reception and transmission timestamps. 219Set the 220.Va net.inet.icmp.tstamprepl 221MIB variable to enable or disable 222.Dv ICMP_TSTAMPREPLY . 223.It Fl m Ar ttl 224Set the IP Time To Live for outgoing packets. 225If not specified, the kernel uses the value of the 226.Va net.inet.ip.ttl 227MIB variable. 228.It Fl n 229Numeric output only. 230No attempt will be made to lookup symbolic names for host addresses. 231.It Fl o 232Exit successfully after receiving one reply packet. 233.It Fl P Ar policy 234.Ar policy 235specifies IPsec policy for the ping session. 236For details please refer to 237.Xr ipsec 4 238and 239.Xr ipsec_set_policy 3 . 240.It Fl p Ar pattern 241You may specify up to 16 242.Dq pad 243bytes to fill out the packet you send. 244This is useful for diagnosing data-dependent problems in a network. 245For example, 246.Dq Li \-p ff 247will cause the sent packet to be filled with all 248ones. 249.It Fl Q 250Somewhat quiet output. 251.No Don Ap t 252display ICMP error messages that are in response to our query messages. 253Originally, the 254.Fl v 255flag was required to display such errors, but 256.Fl v 257displays all ICMP error messages. 258On a busy machine, this output can be overbearing. 259Without the 260.Fl Q 261flag, 262.Nm 263prints out any ICMP error messages caused by its own ECHO_REQUEST 264messages. 265.It Fl q 266Quiet output. 267Nothing is displayed except the summary lines at startup time and 268when finished. 269.It Fl R 270Record route. 271Includes the 272.Tn RECORD_ROUTE 273option in the 274.Tn ECHO_REQUEST 275packet and displays 276the route buffer on returned packets. 277Note that the IP header is only large enough for nine such routes; 278the 279.Xr traceroute 8 280command is usually better at determining the route packets take to a 281particular destination. 282If more routes come back than should, such as due to an illegal spoofed 283packet, ping will print the route list and then truncate it at the correct 284spot. 285Many hosts ignore or discard the 286.Tn RECORD_ROUTE 287option. 288.It Fl r 289Bypass the normal routing tables and send directly to a host on an attached 290network. 291If the host is not on a directly-attached network, an error is returned. 292This option can be used to ping a local host through an interface 293that has no route through it 294(e.g., after the interface was dropped by 295.Xr routed 8 ) . 296.It Fl S Ar src_addr 297Use the following IP address as the source address in outgoing packets. 298On hosts with more than one IP address, this option can be used to 299force the source address to be something other than the IP address 300of the interface the probe packet is sent on. 301If the IP address 302is not one of this machine's interface addresses, an error is 303returned and nothing is sent. 304.It Fl s Ar packetsize 305Specify the number of data bytes to be sent. 306The default is 56, which translates into 64 307.Tn ICMP 308data bytes when combined 309with the 8 bytes of 310.Tn ICMP 311header data. 312Only the super-user may specify values more than default. 313This option cannot be used with ping sweeps. 314.It Fl T Ar ttl 315Set the IP Time To Live for multicasted packets. 316This flag only applies if the ping destination is a multicast address. 317.It Fl t Ar timeout 318Specify a timeout, in seconds, before ping exits regardless of how 319many packets have been received. 320.It Fl v 321Verbose output. 322.Tn ICMP 323packets other than 324.Tn ECHO_RESPONSE 325that are received are listed. 326.It Fl W Ar waittime 327Time in milliseconds to wait for a reply for each packet sent. 328If a reply arrives later, the packet is not printed as replied, but 329considered as replied when calculating statistics. 330.It Fl z Ar tos 331Use the specified type of service. 332.El 333.Pp 334When using 335.Nm 336for fault isolation, it should first be run on the local host, to verify 337that the local network interface is up and running. 338Then, hosts and gateways further and further away should be 339.Dq pinged . 340Round-trip times and packet loss statistics are computed. 341If duplicate packets are received, they are not included in the packet 342loss calculation, although the round trip time of these packets is used 343in calculating the round-trip time statistics. 344When the specified number of packets have been sent 345(and received) 346or if the program is terminated with a 347.Dv SIGINT , 348a brief summary is displayed, showing the number of packets sent and 349received, and the minimum, mean, maximum, and standard deviation of 350the round-trip times. 351.Pp 352If 353.Nm 354receives a 355.Dv SIGINFO 356(see the 357.Cm status 358argument for 359.Xr stty 1 ) 360signal, the current number of packets sent and received, and the 361minimum, mean, and maximum of the round-trip times will be written to 362the standard error output. 363.Pp 364This program is intended for use in network testing, measurement and 365management. 366Because of the load it can impose on the network, it is unwise to use 367.Nm 368during normal operations or from automated scripts. 369.Sh ICMP PACKET DETAILS 370An IP header without options is 20 bytes. 371An 372.Tn ICMP 373.Tn ECHO_REQUEST 374packet contains an additional 8 bytes worth of 375.Tn ICMP 376header followed by an arbitrary amount of data. 377When a 378.Ar packetsize 379is given, this indicated the size of this extra piece of data 380(the default is 56). 381Thus the amount of data received inside of an IP packet of type 382.Tn ICMP 383.Tn ECHO_REPLY 384will always be 8 bytes more than the requested data space 385(the 386.Tn ICMP 387header). 388.Pp 389If the data space is at least eight bytes large, 390.Nm 391uses the first eight bytes of this space to include a timestamp which 392it uses in the computation of round trip times. 393If less than eight bytes of pad are specified, no round trip times are 394given. 395.Sh DUPLICATE AND DAMAGED PACKETS 396The 397.Nm 398utility will report duplicate and damaged packets. 399Duplicate packets should never occur when pinging a unicast address, 400and seem to be caused by 401inappropriate link-level retransmissions. 402Duplicates may occur in many situations and are rarely 403(if ever) 404a good sign, although the presence of low levels of duplicates may not 405always be cause for alarm. 406Duplicates are expected when pinging a broadcast or multicast address, 407since they are not really duplicates but replies from different hosts 408to the same request. 409.Pp 410Damaged packets are obviously serious cause for alarm and often 411indicate broken hardware somewhere in the 412.Nm 413packet's path (in the network or in the hosts). 414.Sh TRYING DIFFERENT DATA PATTERNS 415The 416(inter)network 417layer should never treat packets differently depending on the data 418contained in the data portion. 419Unfortunately, data-dependent problems have been known to sneak into 420networks and remain undetected for long periods of time. 421In many cases the particular pattern that will have problems is something 422that does not have sufficient 423.Dq transitions , 424such as all ones or all zeros, or a pattern right at the edge, such as 425almost all zeros. 426It is not 427necessarily enough to specify a data pattern of all zeros (for example) 428on the command line because the pattern that is of interest is 429at the data link level, and the relationship between what you type and 430what the controllers transmit can be complicated. 431.Pp 432This means that if you have a data-dependent problem you will probably 433have to do a lot of testing to find it. 434If you are lucky, you may manage to find a file that either 435cannot 436be sent across your network or that takes much longer to transfer than 437other similar length files. 438You can then examine this file for repeated patterns that you can test 439using the 440.Fl p 441option of 442.Nm . 443.Sh TTL DETAILS 444The 445.Tn TTL 446value of an IP packet represents the maximum number of IP routers 447that the packet can go through before being thrown away. 448In current practice you can expect each router in the Internet to decrement 449the 450.Tn TTL 451field by exactly one. 452.Pp 453The 454.Tn TCP/IP 455specification recommends setting the 456.Tn TTL 457field for 458.Tn IP 459packets to 64, but many systems use smaller values 460.No ( Bx 4.3 461uses 30, 462.Bx 4.2 463used 15). 464.Pp 465The maximum possible value of this field is 255, and most 466.Ux 467systems set 468the 469.Tn TTL 470field of 471.Tn ICMP ECHO_REQUEST 472packets to 255. 473This is why you will find you can 474.Dq ping 475some hosts, but not reach them with 476.Xr telnet 1 477or 478.Xr ftp 1 . 479.Pp 480In normal operation 481.Nm 482prints the ttl value from the packet it receives. 483When a remote system receives a ping packet, it can do one of three things 484with the 485.Tn TTL 486field in its response: 487.Bl -bullet 488.It 489Not change it; this is what 490.Bx 491systems did before the 492.Bx 4.3 tahoe 493release. 494In this case the 495.Tn TTL 496value in the received packet will be 255 minus the 497number of routers in the round-trip path. 498.It 499Set it to 255; this is what current 500.Bx 501systems do. 502In this case the 503.Tn TTL 504value in the received packet will be 255 minus the 505number of routers in the path 506.Em from 507the remote system 508.Em to 509the 510.Nm Ns Em ing 511host. 512.It 513Set it to some other value. 514Some machines use the same value for 515.Tn ICMP 516packets that they use for 517.Tn TCP 518packets, for example either 30 or 60. 519Others may use completely wild values. 520.El 521.Sh EXIT STATUS 522The 523.Nm 524utility exits with one of the following values: 525.Bl -tag -width indent 526.It 0 527At least one response was heard from the specified 528.Ar host . 529.It 2 530The transmission was successful but no responses were received. 531.It any other value 532An error occurred. 533These values are defined in 534.In sysexits.h . 535.El 536.Sh SEE ALSO 537.Xr netstat 1 , 538.Xr icmp 4 , 539.Xr ifconfig 8 , 540.Xr routed 8 , 541.Xr traceroute 8 542.Sh HISTORY 543The 544.Nm 545utility appeared in 546.Bx 4.3 . 547.Sh AUTHORS 548The original 549.Nm 550utility was written by 551.An Mike Muuss 552while at the US Army Ballistics 553Research Laboratory. 554.Sh BUGS 555Many Hosts and Gateways ignore the 556.Tn RECORD_ROUTE 557option. 558.Pp 559The maximum IP header length is too small for options like 560.Tn RECORD_ROUTE 561to be completely useful. 562.No There Ap s 563not much that can be done about this, however. 564.Pp 565Flood pinging is not recommended in general, and flood pinging the 566broadcast address should only be done under very controlled conditions. 567.Pp 568The 569.Fl v 570option is not worth much on busy hosts. 571