HomeLinuxFind out how to Use Ping Command in Linux with Examples

Find out how to Use Ping Command in Linux with Examples


Ping is an easy, extensively used, cross-platform networking utility for testing if a number is reachable on an Web Protocol (IP) community. It really works by sending a sequence of Web Management Message Protocol (ICMP) ECHO_REQUEST messages to the goal host and ready for an ICMP echo reply (or ECHO_RESPONSE).

You possibly can run a ping take a look at so as to set up in case your laptop can talk with one other laptop (goal host); it helps you identify:

  • Whether or not the goal host is reachable (lively) or not.
  • To measure the period of time it takes for packets to get to the goal host and again to your laptop (the round-trip time (rtt) in speaking with the goal host) and
  • The packet loss is expressed as a proportion.

Its output is a listing of replies from the goal host together with the time taken for the final packet to achieve the goal host and again to your laptop.

It additionally exhibits a statistical abstract of the take a look at, sometimes together with the variety of packets transmitted and people obtained, the share of packet loss; the minimal, most, the imply round-trip instances, and the usual deviation of the imply (mdev). In case a ping take a look at fails, you will notice error messages as output.

Ping Command Examples in Linux

On this article, we’ll clarify 12 sensible ping command examples for testing the reachability of a number on a community.

1. Ping Area or IP Deal with

You possibly can run a easy ping take a look at to see whether or not the goal host www.google.com is reachable or not. You can even use an IP handle as a substitute of the area title as proven.

$ ping www.google.com
OR
$ ping 172.217.27.196

Pattern Output:

ping www.google.com
PING www.google.com (172.217.27.196) 56(84) bytes of knowledge.
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=1 ttl=111 time=5.01 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=2 ttl=111 time=4.75 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=3 ttl=111 time=5.37 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=4 ttl=111 time=4.99 ms
^C
--- www.google.com ping statistics ---
4 packets transmitted, 4 obtained, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 4.751/5.030/5.373/0.222 ms
...

From the outcomes of the above command, the ping was profitable and there have been no packets misplaced. One vital factor to pay attention to, in a ping take a look at output is the time on the finish of every ping reply.

Assuming you might be finishing up ping testing in your servers, then the worth right here issues so much, relying on the kind of software you might be operating on a server.

If, for instance, you might have an internet software the place a single consumer request leads to so many queries to a database(s) to generate outcomes on the UI, then a decrease ping time to that individual server implies extra information is being transmitted with no delay and the alternative is true.

2. Ping Echo Request

You possibly can specify the variety of ECHO_REQUESTs to be despatched after which ping exits, utilizing the -c flag as proven (on this case the ping take a look at will cease after sending 5 packets).

$ ping -c 5 www.google.com

PING www.google.com (172.217.27.196) 56(84) bytes of knowledge.
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=1 ttl=111 time=4.31 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=2 ttl=111 time=4.35 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=3 ttl=111 time=4.06 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=4 ttl=111 time=5.20 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=5 ttl=111 time=4.41 ms

--- www.google.com ping statistics ---
5 packets transmitted, 5 obtained, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 4.064/4.464/5.195/0.383 ms

3. Set Ping Interval Timeout

The -i flag permits you to set intervals in seconds between sending every packet, the default worth is one second.

$ ping -i 3 -c 5 www.google.com

PING www.google.com (172.217.27.196) 56(84) bytes of knowledge.
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=1 ttl=111 time=5.71 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=2 ttl=111 time=6.19 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=3 ttl=111 time=5.39 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=4 ttl=111 time=7.34 ms
64 bytes from bom07s15-in-f4.1e100.web (172.217.27.196): icmp_seq=5 ttl=111 time=4.77 ms

--- www.google.com ping statistics ---
5 packets transmitted, 5 obtained, 0% packet loss, time 12014ms
rtt min/avg/max/mdev = 4.768/5.879/7.341/0.863 ms

4. DoS Assault with Ping Flooding aka Ping of Dying

To find out the response of your community underneath high-load circumstances, you may run a “flood ping” which sends requests as quick as potential, utilizing the -f change. Solely the basis can use this selection, in any other case, use the sudo command to achieve 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 (172.217.163.36) 56(84) bytes of knowledge.
.......................................................................................................................................................................................^C
--- www.google.com ping statistics ---
2331 packets transmitted, 2084 obtained, 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. Ping Broadcast of a LAN

You possibly can allow pinging a broadcast utilizing the -b choice, which is able to get a response from all IP addresses linked to your LAN community.

$ ping -b 192.168.0.0

6. Set Ping TTL Worth

To restrict the variety of community hops (TTLTime-to-live) that probes traverse, use the -t flag. You possibly can set any worth between 1 and 255; completely different working methods set completely different defaults.

Every router that receives the packet subtracts a minimum of 1 from the rely and if the rely remains to be larger than 0, the router forwards the packet to the following hop, in any other case, it discards it and sends an ICMP response again to your laptop.

On this instance, the TTL has been exceeded and the ping take a look at has failed, as proven within the screenshot.

$ ping -t 10 www.google.com
Set Ping TTL Count
Set Ping TTL Rely

7. Set Ping Packet Measurement

The default packet dimension must be ample for a ping take a look at, nonetheless, you may change it to satisfy your particular testing wants. You possibly can specify the scale of the payload, within the variety of bytes utilizing the -s choice, which is able to end in a complete packet dimension of the worth supplied plus 8 additional bytes for the ICMP header.

$ ping -s 1000 www.google.com

8. Set Ping Preload

If preload is added, ping sends that many packets not ready for a reply. Word that solely the basis could choose a preload of greater than 3, in any other case, use the sudo command to achieve root privileges.

$ sudo ping -l 5 www.google.com 

9. Set Ping Timeout

It is usually potential to set the time to attend for a response, in seconds, utilizing the -W choice as proven.

$ ping -W 10 www.google.com

10. Set Ping Timeout in Seconds

To set a timeout in seconds, earlier than ping exits no matter what number of packets have been despatched or obtained, use the -w flag.

$ ping -w 5 www.google.com

11. Ping Debug ICMP Packets

The -d choice permits you to allow the debug IP packet element as proven.

$ ping -d www.google.com

12. Ping Verbose Output

You possibly can allow verbose output utilizing the -v flag, as follows.

$ ping -v www.google.com

Word: Ping could not essentially be used for testing networking connectivity, it merely tells you whether or not an IP handle is lively or inactive.

It’s usually used along with the traceroute program, however, MTR – a contemporary community diagnostic instrument combines the performance of ping and traceroute and provides many further options.

For a complete record of networking instruments, try: Linux Community Administration, Troubleshooting, and Debugging

Abstract

Ping is a quite common technique for troubleshooting the accessibility of hosts on a community. On this article, we’ve defined 12 sensible ping command examples for testing the reachability of a networked system. Share your ideas with us through the remark kind beneath.

If You Recognize What We Do Right here On TecMint, You Ought to Think about:

TecMint is the quickest rising and most trusted neighborhood website for any form of Linux Articles, Guides and Books on the internet. Thousands and thousands of individuals go to TecMint! to go looking or browse the 1000’s of revealed articles accessible FREELY to all.

In the event you like what you might be studying, please think about shopping for us a espresso ( or 2 ) as a token of appreciation.

Support Us

We’re grateful on your by no means ending help.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments