Skip to content

PING

Ping (Packet Internet Groper)

It is a simple, widely used, cross-platform networking utility for testing if a host is reachable on an Internet Protocol (IP) network. It works by sending a series of Internet Control Message Protocol (ICMPECHO_REQUEST messages to the target host and waiting for an ICMP echo reply (or ECHO_RESPONSE).

You can run a ping test in order to establish if your computer can communicate with another computer (target host); it helps you determine:

  • whether the target host is reachable (active) or not,
  • to measure the amount of time it takes for packets to get to the target host and back to your computer (the round-trip time (rtt) in communicating with the target host) and
  • the packet loss, expressed as a percentage.

Its output is a list of replies from the target host along with the time taken for the last packet to reach the target host and back to your computer. It also shows a statistical summary of the test, typically including the number of packets transmitted and those received, percentage of packet loss; the minimum, maximum, the mean round-trip times, and standard deviation of the mean (mdev). In case a ping test fails, you will see error messages as output.

Usage

Ping [options] <ip address>

or

Ping [options] <domain name>

Options

-aAudible ping.
-AAdaptive ping. Interpacket interval adapts to round-trip time, so that effectively not more than one (or more, if preload is set) unanswered probes present in the network. Minimal interval is 200msec for not super-user. On networks with low rtt this mode is essentially equivalent to flood mode.
-bAllow pinging a broadcast address.
-BDo not allow ping to change source address of probes. The address is bound to one selected when ping starts.
-c countStop after sending count ECHO_REQUEST packets. With deadline option, ping waits for count ECHO_REPLY packets, until the timeout expires.
-dSet the SO_DEBUG option on the socket being used. Essentially, this socket option is not used by Linux kernel.
-F flow labelAllocate and set 20 bit flow label on echo request packets. (Only ping6). If value is zero, kernel allocates random flow label.
-fFlood ping. For every ECHO_REQUEST sent a period ”.” is printed, while for ever ECHO_REPLY received a backspace is printed. This provides 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.
-i intervalWait interval seconds between sending each packet. 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 0.2 seconds.
-I interface addressSet source address to specified interface address. Argument may be numeric IP address or name of device. When pinging IPv6 link-local address this option is required.
-l preloadIf preload is specified, ping sends that many packets not waiting for reply. Only the super-user may select preload more than 3.
-LSuppress loopback of multicast packets. This flag only applies if the ping destination is a multicast address.
-nNumeric output only. No attempt will be made to lookup symbolic names for host addresses.
-p patternYou 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.
-Q tosSet Quality of Service -related bits in ICMP datagrams. tos can be either decimal or hex number. Traditionally (RFC1349), these have been interpreted as: 0 for reserved (currently being redefined as congestion control), 1-4 for Type of Service and 5-7 for Precedence. Possible settings for Type of Service are: minimal cost: 0x02, reliability: 0x04, throughput: 0x08, low delay: 0x10. Multiple TOS bits should not be set simultaneously. Possible settings for special Precedence range from priority (0x20) to net control (0xe0). You must be root (CAP_NET_ADMIN capability) to use Critical or higher precedence value. You cannot set bit 0x01 (reserved) unless ECN has been enabled in the kernel. In RFC2474, these fields has been redefined as 8-bit Differentiated Services (DS), consisting of: bits 0-1 of separate data (ECN will be used, here), and bits 2-7 of Differentiated Services Codepoint (DSCP).
-qQuiet output. Nothing is displayed except the summary lines at startup time and when finished.
-RRecord 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.
-rBypass 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.
-s packetsizeSpecifies 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.
-S sndbufSet socket sndbuf. If not specified, it is selected to buffer not more than one packet.
-t ttlSet the IP Time to Live.
-T timestamp optionSet 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).
-M hintSelect Path MTU Discovery strategy. hint 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).
-UPrint 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.
-vVerbose output.
-VShow version and exit.
-w deadlineSpecify 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 packet are sent, it waits either for deadline expire or until count probes are answered or for some error notification from network.
-W timeoutTime to wait for a response, in seconds. The option affects only timeout in absense of any responses, otherwise ping waits for two RTTs.

Examples

  1. You can run a simple ping test to see whether the targe host www.google.com is reachable or not. You can also use an IP address instead of domain name as shown.

$ ping www.google.com

OR

$ ping 216.58.212.78

Sample Output

PING http://www.google.com (172.217.166.164) 56(84) bytes of data.

64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=1 ttl=57 time=2.40 ms

64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=2 ttl=57 time=2.48 ms

64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=3 ttl=57 time=2.43 ms

64 bytes from bom07s20-in-f4.1e100.net (172.217.166.164): icmp_seq=4 ttl=57 time=2.35 ms

^C

http://www.google.com ping statistics —

4 packets transmitted, 4 received, 0% packet loss, time 3004ms

rtt min/avg/max/mdev = 2.353/2.420/2.484/0.058 ms

From the results of the above command, the ping was successful and there were no packets lost. One important thing to take note of, in a ping test output is the time at the end of each ping reply. Assuming you are carrying out a ping testing to your servers, then the value here matters a lot, depending on the type of application you are running on a server.

If, for example, you have a web application where a single user request results into so many queries to a database(s) to generate results on the UI, then a lower ping time to that particular server implies more data is being transmitted without a delay and the opposite is true.

  1. You can specify the number of ECHO_REQUEST’s to be sent after which ping exits, using the -c flag as shown (in this case the ping test will stop after sending 5 packets).

$ ping -c 5 http://www.google.com

PING http://www.google.com (172.217.163.36) 56(84) bytes of data.

64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=1 ttl=56 time=29.7 ms

64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=2 ttl=56 time=29.7 ms

64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=3 ttl=56 time=29.4 ms

64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=4 ttl=56 time=30.2 ms

64 bytes from maa05s01-in-f4.1e100.net (172.217.163.36): icmp_seq=5 ttl=56 time=29.6 ms

http://www.google.com ping statistics —

5 packets transmitted, 5 received, 0% packet loss, time 4004ms

rtt min/avg/max/mdev = 29.499/29.781/30.285/0.307 ms

  1. The -i flag allows you to set interval in seconds between sending each packet, the default value is one second.

$ ping -i 3 -c 5 http://www.google.com

  1. To determine the response of your network under high-load conditions, you can run a “flood ping” which sends requests as fast as possible, using the -f switch. Only root can use this option, otherwise, use the sudo command to gain root privileges.

$ sudo ping -f http://www.google.com

OR

$ sudo ping -f -i 3 http://www.google.com      &nbsp; #specify interval between requests

PING http://www.google.com (172.217.163.36) 56(84) bytes of data.

…………………………………………………………………………………………………………………………………………………………………^C

http://www.google.com ping statistics —

2331 packets transmitted, 2084 received, 10% packet loss, time 34095ms

rtt min/avg/max/mdev = 29.096/29.530/61.474/1.417 ms, pipe 4, ipg/ewma 14.633/29.341 ms

  1. You can enable pinging a broadcast using the -b as shown.

$ ping -b 192.168.43.255

  1. To limit the number of network hops (TTL – Time-to-live) that probes traverse, use the -t flag. You can set any value between 1 and 255; different operating systems set different defaults.

Each router that receives the packet subtracts at least 1 from the count and if the count is still greater than 0, the router forwards the packet to the next hop, otherwise it discards it and sends an ICMP response back to your computer.

In this example, the TTL has been exceeded and the ping test has failed, as shown in the screenshot.

$ ping -t 10 http://www.google.com

Set Ping TTL Count

  1. The default packet size should be sufficient for a ping test, however, you can change it to meet your specific testing needs. You can specify the size of the payload, in number of bytes using the -s option, which will result in a total packet size of value provided plus 8 extra bytes for the ICMP header.

$ ping -s 1000 http://www.google.com

  1. If preload is specified, ping sends that many packets not waiting for reply. Note that only root may select a preload more than 3, otherwise, use the sudo command to gain root privileges.

$ sudo ping -l 5 http://www.google.com

  1. It is also possible to set the time to wait for a response, in seconds, using the -W option as shown.

$ ping -W 10 http://www.google.com

  1. To set a timeout in seconds, before ping exits regardless of how many packets have been sent or received, use the -w flag.

$ ping -w 10 http://www.google.com

  1. The -d option allows you to enable the debug IP packet detail as shown.

$ ping -d http://www.google.com

  1. You can enable verbose output using the -v flag, as follows.

$ ping -v http://www.google.com