{"id":1451,"date":"2019-04-01T17:33:04","date_gmt":"2019-04-01T12:03:04","guid":{"rendered":"http:\/\/jaipurhosting.com\/blog\/?p=1451"},"modified":"2019-04-30T10:43:25","modified_gmt":"2019-04-30T05:13:25","slug":"how-to-use-12-practical-ping-command-examples-in-linux","status":"publish","type":"post","link":"https:\/\/www.jaipurhosting.com\/blog\/how-to-use-12-practical-ping-command-examples-in-linux\/","title":{"rendered":"How to use 12 practical ping command examples in linux"},"content":{"rendered":"\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p><strong>Description <\/strong><\/p>\n\n\n\n<p><strong>Ping<\/strong>&nbsp;is a simple, widely used, cross-platform networking utility for testing if a host is reachable on an&nbsp;<strong>Internet Protocol<\/strong>&nbsp;(<strong>IP<\/strong>) network. <\/p>\n\n\n\n<p>It works by sending a series of&nbsp;<strong>Internet Control Message Protocol<\/strong>&nbsp;(<strong>ICMP<\/strong>)&nbsp;<strong>ECHO_REQUEST<\/strong>&nbsp;messages to the target host and waiting for an&nbsp;<strong>ICMP<\/strong>&nbsp;echo reply (or&nbsp;<strong>ECHO_RESPONSE<\/strong>). <\/p>\n\n\n\n<p>You can run a ping test in order to establish if your computer can communicate with another computer (target host); it helps you determine: <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>whether the target host is reachable (active) or not, <\/li><li>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 (<strong>rtt<\/strong>) in communicating with the target host) and <\/li><li> the packet loss, expressed as a percentage. <\/li><\/ul>\n\n\n\n<p>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. <\/p>\n\n\n\n<p>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). <\/p>\n\n\n\n<p>In case a ping test fails, you will see error messages as output.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Ping Command Examples<\/strong><br><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li> You can run a simple&nbsp;<strong>ping<\/strong>&nbsp;test to see whether the targe host&nbsp;<strong>www.google.com<\/strong> is reachable or not. You can also use an IP address instead of domain name as shown.<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>ping www.google.com<\/em><br><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@server ~]# ping www.google.com\nPING www.google.com (172.217.163.100) 56(84) bytes of data.\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=1 ttl=56 time=3.98 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=2 ttl=56 time=2.83 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=3 ttl=56 time=2.15 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=4 ttl=56 time=2.77 ms\n^C\n--- www.google.com ping statistics ---\n4 packets transmitted, 4 received, 0% packet loss, time 3004ms\nrtt min\/avg\/max\/mdev = 2.152\/2.936\/3.981\/0.660 ms<\/code><\/pre>\n\n\n\n<p>From the results of the above command, the&nbsp;<strong>ping<\/strong>&nbsp;was successful and there were no packets lost. <\/p>\n\n\n\n<p>One important thing to take note of, in a ping test output is the time at the end of each ping reply. <\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<br><\/p>\n\n\n\n<p>2. You can specify the number of&nbsp;<strong>ECHO_REQUEST\u2019s<\/strong>&nbsp;to be sent after which ping exits, using the&nbsp;<code>-c<\/code>&nbsp;flag as shown (in this case the ping test will stop after sending&nbsp;<strong>5<\/strong>&nbsp;packets). <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@server ~]# ping -c 5 www.google.com\nPING www.google.com (172.217.163.100) 56(84) bytes of data.\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=1 ttl=56 time=4.43 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=2 ttl=56 time=2.01 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=3 ttl=56 time=1.90 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=4 ttl=56 time=5.42 ms\n64 bytes from maa05s03-in-f4.1e100.net (172.217.163.100): icmp_seq=5 ttl=56 time=2.33 ms\n\n--- www.google.com ping statistics ---\n5 packets transmitted, 5 received, 0% packet loss, time 4006ms\nrtt min\/avg\/max\/mdev = 1.908\/3.223\/5.425\/1.435 ms<\/code><\/pre>\n\n\n\n<p>3. The&nbsp;<code>-i<\/code>&nbsp;flag allows you to set interval in seconds between sending each packet, the default value is one second. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><em>ping -i 3 -c 5 www.google.com<\/em><br><\/pre>\n\n\n\n<p>4. To determine the response of your network under high-load conditions, you can run a \u201c<strong>flood ping<\/strong>\u201d which sends requests as fast as possible, using the&nbsp;<code>-f<\/code>&nbsp;switch. Only root can use this option, otherwise, use the&nbsp;<strong>sudo command<\/strong>&nbsp;to gain root privileges. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ sudo ping -f www.google.com\nOR\n$ sudo ping -f -i 3 www.google.com\t#specify interval between requests \n\nPING www.google.com (172.217.163.36) 56(84) bytes of data.\n.......................................................................................................................................................................................^C\n--- www.google.com ping statistics ---\n2331 packets transmitted, 2084 received, 10% packet loss, time 34095ms\nrtt min\/avg\/max\/mdev = 29.096\/29.530\/61.474\/1.417 ms, pipe 4, ipg\/ewma 14.633\/29.341 ms<\/code><\/pre>\n\n\n\n<p>5. You can enable pinging a broadcast using the&nbsp;<code>-b<\/code>&nbsp;as shown. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping -b 192.168.43.255<\/code><\/pre>\n\n\n\n<p>6.To limit the number of network hops (<strong>TTL<\/strong>&nbsp;\u2013&nbsp;<strong>Time-to-live<\/strong>) that probes traverse, use the&nbsp;<code>-t<\/code>&nbsp;flag. <\/p>\n\n\n\n<p>You can set any value between&nbsp;<strong>1<\/strong>&nbsp;and&nbsp;<strong>255<\/strong>; different operating systems set different defaults.<\/p>\n\n\n\n<p>Each router that receives the packet subtracts at least&nbsp;<strong>1<\/strong>&nbsp;from the count and if the count is still greater than&nbsp;<strong>0<\/strong>, the router forwards the packet to the next hop, otherwise it discards it and sends an&nbsp;<strong>ICMP<\/strong>&nbsp;response back to your computer.<\/p>\n\n\n\n<p>In this example, the&nbsp;<strong>TTL<\/strong>&nbsp;has been exceeded and the&nbsp;<strong>ping<\/strong>&nbsp;test has failed, as shown in the screenshot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping -t 10 www.google.com<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>[root@server ~]# ping -t 10 www.google.com\nPING www.google.com (216.58.196.164) 56(84) bytes of data.\n64 bytes from maa03s31-in-f4.1e100.net (216.58.196.164): icmp_seq=1 ttl=56 time=1.91 ms\n64 bytes from maa03s31-in-f4.1e100.net (216.58.196.164): icmp_seq=14 ttl=56 time=19.0 ms\n64 bytes from maa03s31-in-f4.1e100.net (216.58.196.164): icmp_seq=15 ttl=56 time=2.21 ms\n^C\n--- www.google.com ping statistics ---\n15 packets transmitted, 14 received, 6% packet loss, time 14019ms\nrtt min\/avg\/max\/mdev = 1.598\/7.269\/19.063\/5.190 ms<\/code><\/pre>\n\n\n\n<p>7. The default packet size should be sufficient for a ping test, however, you can change it to meet your specific testing needs. <\/p>\n\n\n\n<p>You can specify the size of the payload, in number of bytes using the&nbsp;<code>-s<\/code>&nbsp;option, which will result in a total packet size of value provided plus&nbsp;<strong>8<\/strong>&nbsp;extra bytes for the ICMP header. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping -s 1000 www.google.com<\/code><\/pre>\n\n\n\n<p>8. If preload is specified, ping sends that many packets not waiting for reply. Note that only root may select a preload more than&nbsp;<strong>3<\/strong>, otherwise, use the&nbsp;<strong>sudo command<\/strong>&nbsp;to gain root privileges. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo ping -l 5 www.google.com<\/code><\/pre>\n\n\n\n<p>9. It is also possible to set the time to wait for a response, in seconds, using the&nbsp;<code>-W<\/code>&nbsp;option as shown. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ping -W 10 www.google.com<\/code><\/pre>\n\n\n\n<p>10. To set a&nbsp;<strong>timeout<\/strong>&nbsp;in seconds, before ping exits regardless of how many packets have been sent or received, use the&nbsp;<code>-w<\/code>&nbsp;flag. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ping -w 10 www.google.com<\/pre>\n\n\n\n<p>11. The&nbsp;<code>-d<\/code>&nbsp;option allows you to enable the debug IP packet detail as shown. <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ping -d www.google.com<br><\/pre>\n\n\n\n<p>12. You can enable verbose output using the&nbsp;<code>-v<\/code>&nbsp;flag, as follows <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">ping -v www.google.com<\/pre>\n\n\n\n<p><strong>Ping<\/strong>&nbsp;is a very common method for troubleshooting the accessibility of hosts on a network. <\/p>\n\n\n\n<p>In this article, we\u2019ve explained&nbsp;<strong>12<\/strong>&nbsp;practical ping command examples for testing the reachability of a networked device. Share you thoughts with us via the comment form below. <\/p>\n\n\n\n<p>We hope you\u2019ve found this useful! <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Description Ping&nbsp;is a simple, widely used, cross-platform networking utility for testing if a host is reachable on an&nbsp;Internet Protocol&nbsp;(IP) network. It works by sending a series of&nbsp;Internet Control Message Protocol&nbsp;(ICMP)&nbsp;ECHO_REQUEST&nbsp;messages to the target host and waiting for an&nbsp;ICMP&nbsp;echo reply (or&nbsp;ECHO_RESPONSE). You can run a ping test in order to establish if your computer can communicate [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1452,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1451","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/comments?post=1451"}],"version-history":[{"count":2,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1451\/revisions"}],"predecessor-version":[{"id":1454,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/posts\/1451\/revisions\/1454"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media\/1452"}],"wp:attachment":[{"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/media?parent=1451"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/categories?post=1451"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jaipurhosting.com\/blog\/wp-json\/wp\/v2\/tags?post=1451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}