Ping 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 (ICMP) ECHO_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.
Read Also: Fping – A High Performance Ping Tool for Linux
In this article, we will explain 12 practical ping command examples for testing the reachability of a host on a network.
Learn Ping Command 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 18.104.22.168
PING www.google.com (22.214.171.124) 56(84) bytes of data. 64 bytes from bom07s20-in-f4.1e100.net (126.96.36.199): icmp_seq=1 ttl=57 time=2.40 ms 64 bytes from bom07s20-in-f4.1e100.net (188.8.131.52): icmp_seq=2 ttl=57 time=2.48 ms 64 bytes from bom07s20-in-f4.1e100.net (184.108.40.206): icmp_seq=3 ttl=57 time=2.43 ms 64 bytes from bom07s20-in-f4.1e100.net (220.127.116.11): icmp_seq=4 ttl=57 time=2.35 ms ^C --- 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.
2. 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 www.google.com PING www.google.com (18.104.22.168) 56(84) bytes of data. 64 bytes from maa05s01-in-f4.1e100.net (22.214.171.124): icmp_seq=1 ttl=56 time=29.7 ms 64 bytes from maa05s01-in-f4.1e100.net (126.96.36.199): icmp_seq=2 ttl=56 time=29.7 ms 64 bytes from maa05s01-in-f4.1e100.net (188.8.131.52): icmp_seq=3 ttl=56 time=29.4 ms 64 bytes from maa05s01-in-f4.1e100.net (184.108.40.206): icmp_seq=4 ttl=56 time=30.2 ms 64 bytes from maa05s01-in-f4.1e100.net (220.127.116.11): icmp_seq=5 ttl=56 time=29.6 ms --- 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
-i flag allows you to set interval in seconds between sending each packet, the default value is one second.
$ ping -i 3 -c 5 www.google.com
4. 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 www.google.com OR $ sudo ping -f -i 3 www.google.com #specify interval between requests PING www.google.com (18.104.22.168) 56(84) bytes of data. .......................................................................................................................................................................................^C --- 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
5. You can enable pinging a broadcast using the
-b as shown.
$ ping -b 192.168.43.255
6. 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 www.google.com
7. 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 www.google.com
8. 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 www.google.com
9. It is also possible to set the time to wait for a response, in seconds, using the
-W option as shown.
$ ping -W 10 www.google.com
10. To set a timeout in seconds, before ping exits regardless of how many packets have been sent or received, use the
$ ping -w 10 www.google.com
-d option allows you to enable the debug IP packet detail as shown.
$ ping -d www.google.com
12. You can enable verbose output using the
-v flag, as follows.
$ ping -v www.google.com
Note: Ping may not necessarily be used for testing networking connectivity, it simply tells you whether an IP address is active or inactive. It is normally used together with the traceroute program, but, MTR – a modern network diagnostic tool combines the functionality of ping and traceroute and offers many additional features.
For a comprehensive list of networking tools, check out: A Linux Sysadmin’s Guide to Network Management, Troubleshooting and Debugging
Ping is a very common method for troubleshooting the accessibility of hosts on a network. In this article, we’ve explained 12 practical ping command examples for testing the reachability of a networked device. Share you thoughts with us via the comment form below.
4 thoughts on “12 Practical Ping Command Examples for Linux Users”
I just received a new Raspberry Pi Zero and can not ping or ssh to it. I am using the latest versions of Buster Lite and Buster Desktop (not at the same time).
I have used the default DHCP ip address and also set a static ip address. I have connected it to my Ubuntu laptop via USB cable and also connected a Raspberry power supply. The nmap -sn does not show the ip address for this Raspi.
Any suggestions on how I can connect to this machine headless? Do you think that connecting it to the monitor would provide me with any info about it? I currently do not have a mini-HTML cable so will have to get one.
Any particular reason why?
contains both flood and interval options? :)
Welcome, thanks for the feedback.