PING(8)

๐Ÿ’– PING(8) ๐Ÿ’–

the iputils girlies presentโ€ฆ ping โ€” send ICMP ECHO_REQUEST to network hosts โœจ

okay bestie, sit DOWN, because this one is iconic and also lowkey long, so we're doing this properly ๐Ÿซถ


โœจ NAME โœจ

ping โ€” literally just send ICMP ECHO_REQUEST to network hosts ๐Ÿ’…


๐ŸŒธ SYNOPSIS ๐ŸŒธ

ping [-aAbBdDfhLnOqrRUvV46] [-c count] [-F flowlabel] [-i interval]
     [-I interface] [-l preload] [-m mark] [-M pmtudisc_option]
     [-N nodeinfo_option] [-w deadline] [-W timeout] [-p pattern]
     [-Q tos] [-s packetsize] [-S sndbuf] [-t ttl] [-T timestamp option]
     [hop...] {destination}

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to go get an ECHO_RESPONSE out of a host or gateway, periodt. those ECHO_REQUEST datagrams (the "pings", yes the cute little ones ๐ŸŽ€) have an IP and ICMP header, and then a struct timeval, and then an arbitrary number of "pad" bytes that are just there to fill out the packet. filler queen behavior, honestly.

ping works with both IPv4 and IPv6 no cap. if you wanna force just one of them, say the word with -4 or -6.

ping can also send IPv6 Node Information Queries (RFC4620). heads up though: intermediate hops may not be allowed, because IPv6 source routing was deprecated (RFC5095) ๐Ÿ˜ญ rip.


๐Ÿ’… OPTIONS ๐Ÿ’…

okay this is the long part but every single one matters, do not skip, I will know.

  • -4 โ€” IPv4 only. that's it, that's the whole vibe.
  • -6 โ€” IPv6 only. same energy, different protocol ๐Ÿ’œ
  • -a โ€” audible ping. it goes beep and you go "oh ๐Ÿ‘€".
  • -A โ€” adaptive ping. the interpacket interval adapts to round-trip time, so that effectively not more than one unanswered probe is in the network (or more, if preload is set). minimal interval is 200msec unless you're super-user. on networks with low RTT this mode is basically equivalent to flood mode, fr.
  • -b โ€” allow pinging a broadcast address. bold of you, but okay.
  • -B โ€” do not allow ping to change the source address of probes. the address is bound to the one selected when ping starts. commitment issues solved ๐Ÿซถ
  • -c count โ€” stop after sending count ECHO_REQUEST packets. with the deadline option, ping waits for count ECHO_REPLY packets until the timeout expires.
  • -d โ€” set the SO_DEBUG option on the socket being used. ngl, this socket option is essentially not used by the Linux kernel, so it's giving legacy ๐Ÿ’€
  • -D โ€” print a timestamp (unix time + microseconds, as in gettimeofday) before each line. timestamps before it was cool.
  • -f โ€” flood ping. for every ECHO_REQUEST sent a period . is printed, and for every ECHO_REPLY received a backspace is printed. this gives you a rapid display of how many packets are being dropped. if interval isn't given, it sets interval to zero and outputs packets as fast as they come back or one hundred times per second, whichever is more. โš ๏ธ only the super-user may use this option with zero interval.
  • -F flow label โ€” IPv6 only. allocate and set a 20 bit flow label (in hex) on echo request packets. if value is zero, the kernel allocates a random flow label. surprise me energy โœจ
  • -h โ€” show help. we love a helpful queen.
  • -i interval โ€” wait interval seconds between sending each packet. real number allowed, with a dot as the decimal separator (regardless of locale setup). default is to wait for one second between each packet normally, or not to wait in flood mode. only super-user may set interval to values less than 2 ms.
  • -I interface โ€” interface is either an address, an interface name or a VRF name. if interface is an address, it sets the source address to that specified interface address. if interface is an interface name, it sets the source interface to that specified interface. if interface is a VRF name, each packet is routed using the corresponding routing table โ€” and in this case, the -I option can be repeated to specify a source address. NOTE: for IPv6, when doing ping to a link-local scope address, link specification (by the '%'-notation in destination, or by this option) can be used but it is no longer required. glow-up.
  • -l preload โ€” if preload is specified, ping sends that many packets not waiting for reply. only the super-user may select preload more than 3.
  • -L โ€” suppress loopback of multicast packets. this flag only applies if the ping destination is a multicast address. mind your business, loopback ๐Ÿ™ˆ
  • -m mark โ€” use mark to tag the packets going out. useful for a variety of reasons within the kernel, such as using policy routing to select specific outbound processing.
  • -M pmtudisc_opt โ€” select the Path MTU Discovery strategy. pmtudisc_option may be either do (prohibit fragmentation, even local one), want (do PMTU discovery, fragment locally when packet size is large), or dont (do not set DF flag).
  • -N nodeinfo_option โ€” IPv6 only. send ICMPv6 Node Information Queries (RFC4620) instead of Echo Request. CAP_NET_RAW capability is required ๐Ÿ”
    • help โ€” show help for NI support.
    • name โ€” queries for Node Names.
    • ipv6 โ€” queries for IPv6 Addresses. there are several IPv6 specific flags:
      • ipv6-global โ€” request IPv6 global-scope addresses.
      • ipv6-sitelocal โ€” request IPv6 site-local addresses.
      • ipv6-linklocal โ€” request IPv6 link-local addresses.
      • ipv6-all โ€” request IPv6 addresses on other interfaces.
    • ipv4 โ€” queries for IPv4 Addresses. there is one IPv4 specific flag:
      • ipv4-all โ€” request IPv4 addresses on other interfaces.
    • subject-ipv6=ipv6addr โ€” IPv6 subject address.
    • subject-ipv4=ipv4addr โ€” IPv4 subject address.
    • subject-name=nodename โ€” subject name. if it contains more than one dot, a fully-qualified domain name is assumed.
    • subject-fqdn=nodename โ€” subject name. fully-qualified domain name is always assumed.
  • -n โ€” numeric output only. no attempt will be made to lookup symbolic names for host addresses. we're not doing name guessing today ๐Ÿ’…
  • -O โ€” report outstanding ICMP ECHO reply before sending the next packet. this is useful together with the timestamp -D to log output to a diagnostic file and search for missing answers. detective mode ๐Ÿ”
  • -p pattern โ€” you may specify up to 16 "pad" bytes to fill out the packet you send. useful for diagnosing data-dependent problems in a network. for example, -p ff will cause the sent packet to be filled with all ones.
  • -q โ€” quiet output. nothing is displayed except the summary lines at startup time and when finished. lowkey mode, only the receipts at the end ๐Ÿงพ
  • -Q tos โ€” set Quality of Service-related bits in ICMP datagrams. tos can be decimal (ping only) or hex number.
    • in RFC2474, these fields are interpreted as 8-bit Differentiated Services (DS), consisting of: bits 0-1 (2 lowest bits) of separate data, and bits 2-7 (highest 6 bits) of Differentiated Services Codepoint (DSCP). in RFC2481 and RFC3168, bits 0-1 are used for ECN.
    • historically (RFC1349, obsoleted by RFC2474), these were interpreted as: bit 0 (lowest bit) for reserved (currently being redefined as congestion control), 1-4 for Type of Service, and bits 5-7 (highest bits) for Precedence. lore ๐Ÿ›๏ธ
  • -r โ€” bypass the normal routing tables and send directly to a host on an attached interface. if the host is not on a directly-attached network, an error is returned. this option can be used to ping a local host through an interface that has no route through it, provided the option -I is also used.
  • -R โ€” ping only. record route. includes the RECORD_ROUTE option in the ECHO_REQUEST packet and displays the route buffer on returned packets. note that the IP header is only large enough for nine such routes. many hosts ignore or discard this option ๐Ÿ˜ญ
  • -s packetsize โ€” specifies the number of data bytes to be sent. the default is 56, which translates into 64 ICMP data bytes when combined with the 8 bytes of ICMP header data. math slay.
  • -S sndbuf โ€” set socket sndbuf. if not specified, it is selected to buffer not more than one packet.
  • -t ttl โ€” ping only. set the IP Time to Live.
  • -T timestamp option โ€” set special IP timestamp options. timestamp option may be either tsonly (only timestamps), tsandaddr (timestamps and addresses), or tsprespec host1 [host2 [host3 [host4]]] (timestamp prespecified hops).
  • -U โ€” print full user-to-user latency (the old behaviour). normally ping prints network round trip time, which can be different, f.e. due to DNS failures.
  • -v โ€” verbose output. do not suppress DUP replies when pinging a multicast address. give me EVERYTHING ๐Ÿ‘‘
  • -V โ€” show version and exit.
  • -w deadline โ€” specify a timeout, in seconds, before ping exits regardless of how many packets have been sent or received. in this case ping does not stop after count packets are sent โ€” it waits either for deadline to expire, or until count probes are answered, or for some error notification from the network. it's giving "I'll wait, but not forever" ๐Ÿ’”
  • -W timeout โ€” time to wait for a response, in seconds. the option affects only timeout in absence of any responses; otherwise ping waits for two RTTs. real number allowed, with a dot as the decimal separator (regardless of locale setup). 0 means infinite timeout. zero is not a bug it's a lifestyle.

๐ŸŒˆ THE REST OF THE DESCRIPTION (yes there's more, keep up) ๐ŸŒˆ

when you're using ping for fault isolation, run it on the local host FIRST, to verify that the local network interface is up and running. then, hosts and gateways further and further away should be "pinged". round-trip times and packet loss statistics are computed. if duplicate packets are received, they are not included in the packet loss calculation, although the round trip time of these packets IS used in calculating the minimum/average/maximum/mdev round-trip time numbers. every data point pulls its weight ๐Ÿซถ

population standard deviation (mdev) is essentially an average of how far each ping RTT is from the mean RTT. the higher mdev is, the more variable the RTT is (over time). with a high RTT variability, you will have speed issues with bulk transfers โ€” they'll take longer than is strictly speaking necessary, as the variability will eventually cause the sender to wait for ACKs โ€” and you will have middling to poor VoIP quality. so likeโ€ฆ mdev said "consistency is key" and honestly? she's right ๐Ÿ˜ญ

when the specified number of packets have been sent (and received), or if the program is terminated with a SIGINT, a brief summary is displayed. shorter current statistics can be obtained without termination of the process with the signal SIGQUIT. no need to kill the vibe to get the numbers โœจ

if ping does not receive any reply packets at all it will exit with code 1. if a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. on other error it exits with code 2. otherwise it exits with code 0. this makes it possible to use the exit code to see if a host is alive or not. exit codes are literally the receipts of liveness ๐Ÿ’€

โš ๏ธ this program is intended for use in network testing, measurement and management. because of the load it can impose on the network, it is unwise to use ping during normal operations or from automated scripts. put it down, bestie, it's not a toy.

to be continuedโ€ฆ part 2 is coming, don't go anywhere ๐Ÿฆ‹

๐Ÿงธ ICMP PACKET DETAILS ๐Ÿงธ

Okay so let's talk bytes, bestie, because the math here is lowkey adorable.

An IP header with no options is 20 bytes. Periodt. An ICMP ECHO_REQUEST packet then adds 8 more bytes worth of ICMP header, and after that comes however much data you feel like sending. So when you pass a packetsize, that's talking about the size of that extra lil data chunk โ€” and the default is 56. Which means the data you get back inside an IP packet of type ICMP ECHO_REPLY will always be 8 bytes more than the data space you asked for. That's the ICMP header doing its thing, no cap. ๐Ÿ’…

And here's the tea: if that data space is at least as big as struct timeval, ping uses the first bytes of it to stash a timestamp, which it then uses to compute round trip times. If the data space is shorter than that, sorry babe โ€” no round trip times are given. ๐Ÿซ 


๐Ÿ’€ DUPLICATE AND DAMAGED PACKETS ๐Ÿ’€

ping will snitch on duplicate and damaged packets, and honestly? Thank it.

  • Duplicate packets should never happen, like ever. They seem to come from inappropriate link-level retransmissions. They can pop up in lots of situations and are rarely (if ever) a good sign โ€” though low levels of duplicates aren't always a reason to panic. Vibe check: suspicious but maybe survivable. ๐Ÿ™ˆ
  • Damaged packets are, obviously, serious cause for alarm. Like, alarm alarm. They often mean broken hardware somewhere along the ping packet's path โ€” either in the network or in the hosts themselves. ๐Ÿšจ

๐ŸŒˆ TRYING DIFFERENT DATA PATTERNS ๐ŸŒˆ

So the (inter)network layer is supposed to never treat packets differently based on the data inside the data portion. Unfortunately, data-dependent problems have been known to sneak into networks and justโ€ฆ live there, undetected, for long periods of time. Iconic in the worst way. ๐Ÿ˜ญ

In many cases the pattern that causes problems is one that doesn't have enough "transitions" โ€” think all ones or all zeros, or a pattern right at the edge, like almost all zeros. And here's the tricky part: it isn't necessarily enough to specify a data pattern of all zeros on the command line, because the pattern that actually matters is at the data link level, and the relationship between what you type and what the controllers transmit can get complicated. ๐Ÿ˜ตโ€๐Ÿ’ซ

Which means: if you have a data-dependent problem, you're probably gonna have to do a LOT of testing to find it. But if you're lucky, you might find a file that either can't be sent across your network at all, or that takes way longer to transfer than other files of similar length. Then you can go examine that file for repeated patterns and test them using the -p option of ping. Detective era. ๐Ÿ”โœจ


โณ TTL DETAILS โณ

The TTL value of an IP packet is the maximum number of IP routers that packet can go through before it gets yeeted into the void. In current practice, you can expect each router in the Internet to decrement the TTL field by exactly one.

The TCP/IP specification says the TTL field for TCP packets should be set to 60, but many systems use smaller values (4.3 BSD uses 30, 4.2 used 15). The maximum possible value of this field is 255, and most Unix systems set the TTL field of ICMP ECHO_REQUEST packets to 255. Which is exactly why you'll find you can "ping" some hosts but can't reach them with telnet(1) or ftp(1). It's giving exclusive access. ๐Ÿ’…

In normal operation, ping prints the TTL value from the packet it receives. And when a remote system receives a ping packet, it can do one of three things with the TTL field in its response:

  • Not change it โ€” this is what Berkeley Unix systems did before the 4.3BSD Tahoe release. In this case the TTL value in the received packet will be 255 minus the number of routers in the round-trip path.
  • Set it to 255 โ€” this is what current Berkeley Unix systems do. In this case the TTL value in the received packet will be 255 minus the number of routers in the path from the remote system to the pinging host.
  • Set it to some other value โ€” some machines use the same value for ICMP packets that they use for TCP packets, like either 30 or 60. Others may use completely wild values. Main character chaos energy, honestly. ๐ŸŒช๏ธ

๐Ÿ› BUGS ๐Ÿ›

  • Many Hosts and Gateways ignore the RECORD_ROUTE option. Rude.
  • The maximum IP header length is too small for options like RECORD_ROUTE to be completely useful. There's not much that can be done about this, however. ๐Ÿ˜”
  • Flood pinging is not recommended in general, and flood pinging the broadcast address should only be done under very controlled conditions.
โš ๏ธ Bestie, for real: that last one is not a drill. Flood ping on a broadcast address without very controlled conditions is a chaos move.

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

ip(8), ss(8).


๐Ÿ“œ HISTORY ๐Ÿ“œ

The ping command appeared in 4.3BSD.

The version described here is its descendant specific to Linux. ๐ŸŒˆ

As of version s20150815, the ping6 binary doesn't exist anymore โ€” it's been merged into ping. Creating a symlink named ping6 pointing to ping will result in the same functionality as before. Slay, consolidation. โœจ


๐Ÿ” SECURITY ๐Ÿ”

ping requires CAP_NET_RAW capability to be executed:

  1. if the program is used for non-echo queries (see the -N option), or
  2. if the kernel does not support non-raw ICMP sockets, or
  3. if the user is not allowed to create an ICMP echo socket.

The program may be used as set-uid root.


๐Ÿ“ฆ AVAILABILITY ๐Ÿ“ฆ

ping is part of the iputils package.


okay bestie that's the whole page, you're officially fluent ๐Ÿ’– this little love letter to you is from the iputils crew โ€” version 20211215, all dressed up as PING(8) and dated 20211215. go ping something and be iconic ๐Ÿซถ

๐Ÿ“ฆ where this page comes from