12 Ping Command Examples to Test Your Network

Introduction

The ping command is a useful tool for testing the reachability of a host on an Internet Protocol (IP) network. It works by sending ICMP (Internet Control Message Protocol) echo request packets to the target host and waiting for an ICMP response. In this article, we will discuss 12 ping command examples to test your network. We will cover how to use the ping command to test the reachability of a host, how to use the ping command to measure latency, and how to use the ping command to troubleshoot network issues. We will also discuss some of the most common ping command options and how to interpret the output of the ping command.

12 Ping Command Examples to Test Your Network

1. Ping localhost:

ping localhost

2. Ping a website:

ping www.example.com

3. Ping a specific IP address:

ping 192.168.1.1

4. Ping a hostname:

ping myhostname

5. Ping a range of IP addresses:

ping 192.168.1.1-192.168.1.10

6. Ping a broadcast address:

ping 192.168.1.255

7. Ping a multicast address:

ping 224.0.0.1

8. Ping a specific port:

ping -p 80 192.168.1.1

9. Ping with a specific packet size:

ping -s 1024 192.168.1.1

10. Ping with a specific time-to-live (TTL):

ping -t 64 192.168.1.1

11. Ping with a specific timeout:

ping -w 10 192.168.1.1

12. Ping with a specific number of packets:

ping -c 5 192.168.1.1
[ad_1]

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 is 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, the percentage of packet loss; the minimum, maximum, the mean round-trip times, and the standard deviation of the mean (mdev). In case a ping test fails, you will see error messages as output.

Ping Command Examples in Linux

In this article, we will explain 12 practical ping command examples for testing the reachability of a host on a network.

1. Ping Domain or IP Address

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

$ ping www.google.com
OR
$ ping 172.217.27.196

Sample Output:

ping www.google.com
PING www.google.com (172.217.27.196) 56(84) bytes of data.
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=1 ttl=111 time=5.01 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=2 ttl=111 time=4.75 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=3 ttl=111 time=5.37 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=4 ttl=111 time=4.99 ms
^C
--- www.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 4.751/5.030/5.373/0.222 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 ping testing on 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 in 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. Ping Echo Request

You can specify the number of ECHO_REQUESTs 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 (172.217.27.196) 56(84) bytes of data.
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=1 ttl=111 time=4.31 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=2 ttl=111 time=4.35 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=3 ttl=111 time=4.06 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=4 ttl=111 time=5.20 ms
64 bytes from bom07s15-in-f4.1e100.net (172.217.27.196): icmp_seq=5 ttl=111 time=4.41 ms

--- www.google.com ping statistics ---
5 packets transmitted, 5 received, 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 allows you to set intervals in seconds between sending each packet, the default value is one second.

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

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

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

4. DoS Attack with Ping Flooding aka Ping of Death

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 the 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 (172.217.163.36) 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. Ping Broadcast of a LAN

You can enable pinging a broadcast using the -b option, which will get a response from all IP addresses connected to your LAN network.

$ ping -b 192.168.0.0

6. Set Ping TTL Value

To limit the number of network hops (TTLTime-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
Set Ping TTL Count
Set Ping TTL Count

7. Set Ping Packet Size

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 the number of bytes using the -s option, which will result in a total packet size of the value provided plus 8 extra 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 waiting for a reply. Note that only the root may select a preload of more than 3, otherwise, use the sudo command to gain root privileges.

$ sudo ping -l 5 www.google.com 

9. Set Ping Timeout

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. Set Ping Timeout in Seconds

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 5 www.google.com

11. Ping Debug ICMP Packets

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

$ ping -d www.google.com

12. Ping Verbose Output

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: Linux Network Management, Troubleshooting, and Debugging

Summary

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 your thoughts with us via the comment form below.

If You Appreciate What We Do Here On Jassweb, You Should Consider:

Jassweb is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit Jassweb! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

[ad_2]

12 Ping Command Examples to Test Your Network

Ping is a network utility used to test the reachability of a host on an Internet Protocol (IP) network. It works by sending ICMP “echo request” packets to the target host and listening for ICMP “echo response” replies. In this article, we will discuss 12 examples of the ping command.

1. Basic Ping Command

The most basic form of the command is:

ping <host>

Where <host> is either a website URL or an IP address. For example, to ping the website example.com, you would type:

ping example.com

2. Ping with a Specific Number of Packets

By default, the ping command sends four packets. You can specify a different number of packets with the -n option. For example, to send 10 packets, you would type:

ping -n 10 example.com

3. Ping with a Timeout

By default, the ping command will wait indefinitely for a response. You can specify a timeout with the -w option. The timeout is specified in milliseconds. For example, to set a timeout of 5 seconds, you would type:

ping -w 5000 example.com

4. Ping with a Packet Size

By default, the ping command sends packets with a size of 32 bytes. You can specify a different packet size with the -l option. The size is specified in bytes. For example, to send packets with a size of 64 bytes, you would type:

ping -l 64 example.com

5. Ping with a Time Interval

By default, the ping command sends packets at intervals of one second. You can specify a different interval with the -i option. The interval is specified in seconds. For example, to send packets at an interval of 5 seconds, you would type:

ping -i 5 example.com

6. Ping with a Record Route

The -r option allows you to specify a record route. This will cause the ping command to record the route of the packets. For example, to record the route of the packets, you would type:

ping -r example.com

7. Ping with a Timestamp

The -t option allows you to specify a timestamp. This will cause the ping command to include a timestamp in the packets. For example, to include a timestamp in the packets, you would type:

ping -t example.com

8. Ping with a Source Address

The -S option allows you to specify a source address. This will cause the ping command to use the specified address as the source of the packets. For example, to use the address 192.168.1.1 as the source of the packets, you would type:

ping -S 192.168.1.1 example.com

9. Ping with a Don’t Fragment Flag

The -f option allows you to specify a don’t fragment flag. This will cause the ping command to set the don’t fragment flag in the packets. For example, to set the don’t fragment flag in the packets, you would type:

ping -f example.com

10. Ping with a Verbose Output

The -v option allows you to specify a verbose output. This will cause the ping command to display detailed information about the packets. For example, to display detailed information about the packets, you would type:

ping -v example.com

11. Ping with a Debug Output

The -d option allows you to specify a debug output. This will cause the ping command to display debugging information about the packets. For example, to display debugging information about the packets, you would type:

ping -d example.com

12. Ping with a Quiet Output

The -q option allows you to specify a quiet output. This will cause the ping command to display only the summary information about the packets. For example, to display only the summary information about the packets, you would type:

ping -q example.com

These are just a few examples of the ping command. For more information, consult the ping command manual page.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00