PING(8)

๐Ÿ’– ping โ€” the manual, but make it cute ๐Ÿ’–

ok so bestie. this is PING(8) from the iputils gang, and it's literally the most iconic networking tool to ever exist. no cap. let's get into it ๐Ÿซถ


โœจ NAME โœจ

ping โ€” send ICMP ECHO_REQUEST to network hosts

like. that's it. that's the whole job. you yell at a host, it yells back. iconic behaviour honestly ๐ŸŒˆ


โœจ SYNOPSIS โœจ

ping [-aAbBdCDfhHLnOqrRUvV346] [-c count] [-e identifier] [-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}

look at all those little flag-letters. it's giving alphabet soup but every single one of them does something. we'll get to them, don't worry ๐Ÿ’…


โœจ DESCRIPTION โœจ

okay so here's the tea ๐Ÿ“

ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit an ECHO_RESPONSE from a host or gateway. yes mandatory, as in the protocol requires it, as in it's not optional, as in it's the law. the ECHO_REQUEST datagrams โ€” aka the โ€œpingsโ€, the little guys, the whole point โ€” have an IP and ICMP header, followed by a struct timeval, and then an arbitrary number of โ€œpadโ€ bytes used to fill out the packet.

so the anatomy is basically:

  1. IP header
  2. ICMP header
  3. struct timeval
  4. as many โ€œpadโ€ bytes as it takes to fill out the packet โœจ
ngl the pad bytes are just there to fill space and honestly? relatable. main character energy in an empty room ๐Ÿ’€

ping works with both IPv4 and IPv6, bestie. it's bilingual. it contains multitudes ๐Ÿฆ‹

and if you wanna force it to use only one of them explicitly, you can โ€” just specify -4 or -6. crisis averted, no ambiguity, pick your lane.

ping can also send IPv6 Node Information Queries (RFC4620). fancy. but heads up: intermediate hops may not be allowed, because IPv6 source routing was deprecated (RFC5095).

๐Ÿšฉ deprecated means deprecated, bestie. that's not a vibe check, that's a protocol-level "we don't do that anymore." don't come for me, come for the RFC.

ok that's part one, we're just getting warmed up, there's so much more coming ๐ŸŒธ

โœจ OPTIONS โœจ

okay bestie this is the part where it gets long but it's literally all the good stuff, don't skip any of it, we're going through ALL of them ๐Ÿ’…

  • -3 โ€” RTT precision, meaning it does not round up the result time. no rounding, we're being precise โœจ
  • -4 โ€” IPv4 only. periodt.
  • -6 โ€” IPv6 only. also periodt.
  • -a โ€” Audible ping. it makes noise so you know what's up ๐Ÿ””
  • -A โ€” Adaptive ping. the interpacket interval literally adapts to the round-trip time, so that effectively there's not more than one unanswered probe chilling in the network (or more than one, if preload is set ๐Ÿ‘€). default interval is 2 ms, more deets in the -i option. on networks with low RTT this mode is essentially equivalent to flood mode, no cap.
  • -b โ€” Allow pinging a broadcast address. let it hit everyone ๐Ÿซถ
  • -B โ€” Do not allow ping to change the source address of probes. the address is bound to the one selected when ping starts, so it's locked in, main character energy, no switching up.
  • -c count โ€” Stop after sending count ECHO_REQUEST packets. with the deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.
  • -C โ€” Call connect() syscall on socket creation.
  • -d โ€” Set the SO_DEBUG option on the socket being used. honestly? this socket option is essentially not used by the Linux kernel. so like, it's giving decorative.
  • -D โ€” Print a timestamp (unix time + microseconds, as in gettimeofday) before each line. time-stamped receipts ๐Ÿ“Œ
  • -e identifier โ€” Set the identification field of ECHO_REQUEST. a value of 0 implies using a raw socket (not supported on ICMP datagram socket). the value of this field may be printed with the -v option.
  • -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 is not 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 the value is zero, the kernel allocates a random flow label. cute of it.
  • -h โ€” Show help.
  • -H โ€” Force DNS name resolution for the output. useful for a numeric destination, or for the -f option, which by default do not perform it. it can also help to workaround DNS resolution problems. overrides a previously defined -n option. see also the IPUTILS_PING_PTR_LOOKUP environment variable.
  • -i interval โ€” Wait interval seconds between sending each packet. a real number is allowed, with a dot as the decimal separator (regardless of locale setup โ€” yes, regardless, don't fight it). the 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. broadcast and multicast ping have an even higher limitation for a regular user: the minimum is 1 sec.
  • -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 the specified interface address. if interface is an interface name, it sets the source interface to the specified interface. if interface is a VRF name, each packet is routed using the corresponding routing table; in this case, the -I option can be repeated to specify a source address. NOTE: for IPv6, when pinging 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 without waiting for a reply. Only the super-user may select a preload more than 3.
  • -L โ€” Suppress loopback of multicast packets. this flag only applies if the ping destination is a multicast address.
  • -m mark โ€” use mark to tag the packets going out. this is useful for a variety of reasons within the kernel, such as using policy routing to select specific outbound processing. CAP_NET_ADMIN or CAP_NET_RAW (since Linux 5.17) capability is required, see socket(7).
  • -M pmtudisc_opt โ€” Select the Path MTU Discovery strategy. pmtudisc_option may be either do (set DF flag but subject to PMTU checks by kernel โ€” packets too large will be rejected), want (do PMTU discovery, fragment locally when packet size is large), probe (set DF flag and bypass PMTU checks, useful for probing), or dont (do not set DF flag).
  • -N nodeinfo_option โ€” IPv6 only. Send IPv6 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. a fully-qualified domain name is always assumed.
  • -n โ€” Numeric output only. no attempt will be made to lookup symbolic names for host addresses (so, no reverse DNS resolution). this is the default for a numeric destination or the -f option. overrides a previously defined -H option. see also the IPUTILS_PING_PTR_LOOKUP environment variable.
  • -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. this is useful for diagnosing data-dependent problems in a network. for example, -p ff will cause the sent packet to be filled with all ones. ff = all the ones, iconic.
  • -q โ€” Quiet output. nothing is displayed except the summary lines at startup time and when finished. silent but deadly ๐Ÿ’€
  • -Q tos โ€” Set Quality of Service-related bits in ICMP datagrams. tos can be a decimal (ping only) or hex number.

In RFC2474, these fields are interpreted as 8-bit Differentiated Services (DS), consisting of: bits 0-1 (the 2 lowest bits) of separate data, and bits 2-7 (the 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 drop ๐Ÿ“œ

  • -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. rude of them honestly.
  • -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. the maximum allowed value is 65507 for IPv4 (65467 when -R or -T or Intermediate hops) or 65527 for IPv6, but most systems limit this to a smaller, system-dependent number.
  • -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.
  • -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.
  • -W timeout โ€” Time to wait for a response, in seconds. the option affects only timeout in the absence of any responses, otherwise ping waits for two RTTs. a real number is allowed, with a dot as the decimal separator (regardless of locale setup). 0 means infinite timeout. ๐Ÿ•ฐ๏ธ

okay so when you're using ping for fault isolation, bestie, you should first run it on the local host, 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.

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 will 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... jittery network = bad vibes on your calls, fr fr ๐Ÿ˜ญ

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 terminating the process, with the signal SIGQUIT. ๐ŸŽ€

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. like please don't, it's not that kind of party.

๐ŸŒธ ENVIRONMENT ๐ŸŒธ

  • IPUTILS_PING_PTR_LOOKUP โ€” environment variable set to 0 disables reverse DNS resolution (PTR lookup) by default. it will be overrided by the -H or -n option.

๐Ÿ’€ EXIT STATUS ๐Ÿ’€

ok so here's the tea on how ping says goodbye ๐Ÿ‘‹ โ€” the exit code is literally a vibe check on whether your host is alive or not, no cap.

  • If ping does not receive any reply packets at all, it exits with code 1.
  • If a packet count and a deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it also exits with code 1.
  • On any 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. fr fr, scriptable queen behavior ๐Ÿ‘‘


For IPv6, when the destination address has link-local scope and ping is using ICMP datagram sockets, the output interface must be specified. ๐Ÿ˜ค

When ping is using raw sockets, it is not strictly necessary to specify the output interface โ€” but it should be done to avoid ambiguity when there are multiple possible output interfaces. iykyk.

There are two ways to specify the output interface:

  • using the % notation โ€” the destination address is postfixed with % and the output interface name or ifindex, for example:
ping fe80::5054:ff:fe70:67bc%eth0
ping fe80::5054:ff:fe70:67bc%2
  • using the -I option โ€” when using ICMP datagram sockets, this method is supported since the following kernel versions: 5.17, 5.15.19, 5.10.96, 5.4.176, 4.19.228, 4.14.265. Also it is not supported on musl libc. ๐Ÿ™ˆ

๐ŸŒธ ICMP PACKET DETAILS ๐ŸŒธ

An IP header without options is 20 bytes. An ICMP ECHO_REQUEST packet contains an additional 8 bytes worth of ICMP header followed by an arbitrary amount of data. ๐ŸŽ€

When a packetsize is given, this indicates the size of this extra piece of data โ€” and the default is 56. Thus the amount of data received inside of an IP packet of type ICMP ECHO_REPLY will always be 8 bytes more than the requested data space (the ICMP header). math is mathing ๐Ÿ“

If the data space is at least of size of struct timeval, ping uses the beginning bytes of this space to include a timestamp which it uses in the computation of round trip times. If the data space is shorter, no round trip times are given. ๐Ÿ˜ญ


๐Ÿ™ˆ DUPLICATE AND DAMAGED PACKETS ๐Ÿ™ˆ

ping will report duplicate and damaged packets.

Duplicate packets should never occur, and seem to be caused by inappropriate link-level retransmissions. Duplicates may occur in many situations and are rarely (if ever) a good sign โ€” although the presence of low levels of duplicates may not always be cause for alarm. like, it's giving concerning but maybe chill ๐Ÿซ 

Damaged packets are obviously serious cause for alarm and often indicate broken hardware somewhere in the ping packet's path โ€” in the network or in the hosts. ๐Ÿšจ


๐Ÿ’… ID COLLISIONS ๐Ÿ’…

Unlike TCP and UDP, which use port to uniquely identify the recipient to deliver data, ICMP uses the identifier field (ID) for identification. So if, on the same machine, at the same time, two ping processes use the same ID, the echo reply can be delivered to a wrong recipient. ๐Ÿ’€

This is a known problem due to the limited size of the 16-bit ID field. That is a historical limitation of the protocol that cannot be fixed at the moment unless we encode an ID into the ping packet payload. ping prints DIFFERENT ADDRESS error and packet loss is negative. not the negative packet loss ๐Ÿ˜ญ

ping uses PID to get a unique number. The default value of /proc/sys/kernel/pid_max is 32768. On the systems that use ping heavily and with pid_max greater than 65535, collisions are bound to happen.


๐Ÿงš TRYING DIFFERENT DATA PATTERNS ๐Ÿงš

The (inter)network layer should never treat packets differently depending on the data contained in the data portion. Unfortunately, data-dependent problems have been known to sneak into networks and remain undetected for long periods of time. ๐Ÿ˜”

In many cases the particular pattern that will have problems is something that doesn't have sufficient "transitions" โ€” such as all ones or all zeros, or a pattern right at the edge, such as almost all zeros. It isn't necessarily enough to specify a data pattern of all zeros (for example) on the command line because the pattern that is of interest is at the data link level, and the relationship between what you type and what the controllers transmit can be complicated. it's giving layers upon layers ๐Ÿง…

This means that if you have a data-dependent problem you will probably have to do a lot of testing to find it. If you are lucky ๐Ÿ€, you may manage to find a file that either can't be sent across your network or that takes much longer to transfer than other similar length files. You can then examine this file for repeated patterns that you can test using the -p option of ping. slay, detective era ๐Ÿ”


โญ TTL DETAILS โญ

The TTL value of an IP packet represents the maximum number of IP routers that the packet can go through before being thrown away. In current practice you can expect each router in the Internet to decrement the TTL field by exactly one.

The TTL field for TCP packets may take various values. The maximum possible value of this field is 255, and a recommended initial value is 64. For more information, see the TCP/Lower-Level Interface section of RFC9293. ๐Ÿ“š

In normal operation ping prints the TTL value from the packet it receives. 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, for example either 30 or 60. Others may use completely wild values. ๐Ÿคช main character energy, honestly

๐Ÿ˜ญ BUGS ๐Ÿ˜ญ

  • Many Hosts and Gateways ignore the RECORD_ROUTE option.
  • 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, pls do not flood ping the broadcast address on a whim. that's not a cute look, that's a whole incident. ๐Ÿšซ

๐Ÿ‘‘ 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 has been merged into ping. Creating a symlink named ping6 pointing to ping will result in the same functionality as before. the way they just merged them, iconic ๐Ÿ’…


๐Ÿ”ฅ SECURITY ๐Ÿ”ฅ

ping requires CAP_NET_RAW capability to be executed:

  1. if the program is used for non-echo queries (see -N option) or when the identification field set to 0 for ECHO_REQUEST (see -e), or
  2. if kernel does not support ICMP datagram 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.


and that's the whole page, bestie!! ๐ŸŽ€ you just read the iputils 20250605 version of PING(8) โ€” yes that's the source and version, and yes she's serving section-8 realness. go ping something and be free ๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from