{"id":4800,"date":"2018-06-12T18:07:05","date_gmt":"2018-06-12T14:07:05","guid":{"rendered":"https:\/\/www.howtoforge.com\/linux-ping-command\/"},"modified":"2018-06-12T18:07:05","modified_gmt":"2018-06-12T14:07:05","slug":"linux-ping-command-tutorial-for-beginners-8-examples","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/linux-ping-command-tutorial-for-beginners-8-examples\/","title":{"rendered":"Linux ping Command Tutorial for Beginners (8 Examples)"},"content":{"rendered":"<p>Regardless of the type of Linux user you are (beginner or pro), there are certain tools that you must be aware of. One such utility is <strong>Ping<\/strong>. In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples in the article here have been tested on an Ubuntu 16.04 LTS machine.<\/p>\n<h2 id=\"linux-ping-command\">Linux ping command<\/h2>\n<p>In most basic terms, the ping command lets you check whether or not a remote host is alive and responding. Following is the tool&#8217;s syntax:<\/p>\n<p class=\"command\">ping [OPTIONS] destination<\/p>\n<p>And here&#8217;s how the man page explains it:<\/p>\n<pre readability=\"9\"> ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to elicit<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 an ICMP ECHO_RESPONSE from a host or gateway.\u00a0\u00a0 ECHO_REQUEST\u00a0 datagrams<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 (``pings'')\u00a0 have\u00a0 an\u00a0 IP and ICMP header, followed by a struct timeval<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 and then an arbitrary number of ``pad'' bytes\u00a0 used\u00a0 to\u00a0 fill\u00a0 out\u00a0 the<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 packet.<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ping6\u00a0 is\u00a0 IPv6\u00a0 version\u00a0 of\u00a0 ping,\u00a0 and can also send Node Information<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Queries (RFC4620).\u00a0 Intermediate hops may not be allowed, because\u00a0 IPv6<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 source routing was deprecated (RFC5095).<\/p><\/pre>\n<p>Following are some Q&amp;A-styled examples that should give you a good idea on how the ping command works.<\/p>\n<h2 id=\"q-how-to-use-ping-command\">Q1. How to use ping command?<\/h2>\n<p>Basic usage is fairly easy &#8211; just execute the &#8216;ping&#8217; command with destination as input.<\/p>\n<p>For example:<\/p>\n<p class=\"command\">ping howtoforge.com<\/p>\n<p>Following is the result of this command produced on my system:<\/p>\n<p><a class=\"fancybox\" id=\"img-ping-basic\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ping-basic.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples.png\" alt=\"How to use ping command\" width=\"500\" height=\"167\" title=\"\"><\/a><\/p>\n<p>Note that by default, the command will continue executing until you stop it through Ctrl+C.<\/p>\n<h2 id=\"q-how-to-change-time-interval-between-ping-packets\">Q2. How to change time interval between ping packets?<\/h2>\n<p>By default, there&#8217;s a gap of one second between ping packets. However, if you want, you can customize this delay using the -i command line option.<\/p>\n<p>For example, the following command makes sure there&#8217;s a gap of 3 seconds:<\/p>\n<p class=\"command\">ping -i 3 howtoforge.com<\/p>\n<p>And the following command sends packets with a delay of half-a-second.<\/p>\n<p class=\"command\">ping -i 0.5 howtoforge.com<\/p>\n<p>Note that only super-user may set interval to values less 0.2 seconds<\/p>\n<h2 id=\"q-how-to-change-ping-packet-size\">Q3. How to change ping packet size?<\/h2>\n<p>By default, the number of bytes in a ping packet is 56 (64 if you include 8 bytes of ICMP header). However, if you want, you change this value, something which you can do using the -s command line option.<\/p>\n<p>For example, to send an 80 byte packet (88 including ICMP header), use the following command:<\/p>\n<p class=\"command\">ping -s 80 howtoforge.com<\/p>\n<p><a class=\"fancybox\" id=\"img-ping-s-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ping-s-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-1.png\" alt=\"How to change ping packet size\" width=\"500\" height=\"122\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-make-ping-send-set-number-of-packets\">Q4. How to make ping send set number of packets?<\/h2>\n<p>The default behavior of ping is to keep sending packets until interrupted by the user. However, if you want, you can force ping to stop executing after sending a set number of packets. This you can do using the -c command line option.<\/p>\n<p>For example, the following command will send 3 packets and then stop.<\/p>\n<p class=\"command\">ping -c 3 howtoforge.com<\/p>\n<h2 id=\"q-how-to-launch-a-flood-of-packets-using-ping\">Q5. How to launch a flood of packets using ping?<\/h2>\n<p>Yes, the ping command also offers an option to launch a flood of packets. This you can do using the -f command line option.<\/p>\n<p class=\"command\">ping -f howtoforge.com<\/p>\n<p>Here&#8217;s what the official docs say about this option:<\/p>\n<pre> For\u00a0 every\u00a0 ECHO_REQUEST\u00a0 sent\u00a0 a\u00a0 period\u00a0 ``.''\u00a0 is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 printed,\u00a0 while\u00a0 for\u00a0 ever\u00a0 ECHO_REPLY\u00a0 received\u00a0 a backspace is<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 printed.\u00a0 This provides a rapid display of how many packets\u00a0 are<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 being\u00a0 dropped.\u00a0\u00a0 If\u00a0 interval is not given, it sets interval to<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 zero and outputs packets as fast as they come back or\u00a0 one\u00a0 hun?<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 dred\u00a0 times\u00a0 per second, whichever is more.\u00a0 Only the super-user<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 may use this option with zero interval.<\/pre>\n<h2 id=\"q-how-to-make-ping-print-timestamp-before-each-line\">Q6. How to make ping print timestamp before each line?<\/h2>\n<p>There&#8217;s an option (-D) that lets you do this. The timestamp that&#8217;s printed is a combination of unix time and microseconds (as in gettimeofday).<\/p>\n<p class=\"command\">ping -D howtoforge.com<\/p>\n<p>Here&#8217;s a screenshot of this option in action:<\/p>\n<p><a class=\"fancybox\" id=\"img-ping-D-option\" href=\"https:\/\/www.howtoforge.com\/images\/command-tutorial\/big\/ping-D-option.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-2.png\" alt=\"How to make ping print timestamp before each line\" width=\"500\" height=\"124\" title=\"\"><\/a><\/p>\n<h2 id=\"q-how-to-set-a-hard-timeout-for-ping\">Q7. How to set a hard timeout for ping?<\/h2>\n<p>You can specify a time deadline for ping to exit. This you can do using the -w command line option that requires a numeric value representing number of seconds.<\/p>\n<p>For example, the following ping command will stop after 3 seconds:<\/p>\n<p class=\"command\">ping -w 3 howtoforge.com<\/p>\n<p>Here&#8217;s how the official docs explain this option:<\/p>\n<pre> Specify\u00a0 a\u00a0 timeout, in seconds, before ping exits regardless of<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 how many packets have been sent or received. In this\u00a0 case\u00a0 ping<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 does\u00a0 not\u00a0 stop after count packet are sent, it waits either for<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 deadline expire or until count probes are answered or\u00a0 for\u00a0 some<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 error notification from network.<\/pre>\n<h2 id=\"q-how-to-set-a-soft-timeout-for-ping\">Q8. How to set a soft timeout for ping?<\/h2>\n<p>While the -w option makes sure ping stops in any case after the deadline has expired, there&#8217;s another option (-W, in caps) that also makes ping stop but only when there&#8217;s no response from the destination side.<\/p>\n<p class=\"command\">ping -W 3 howtoforge.com<\/p>\n<p>Here&#8217;s how the man page explains the behavior in this case:<\/p>\n<pre> Time to wait for a response, in seconds. The option affects only<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 timeout in absence of any responses, otherwise\u00a0 ping\u00a0 waits\u00a0 for<br\/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 two RTTs.<\/pre>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>Ping is an important tool that almost certainly used in debugging network-related issues. In this tutorial, we discussed some main features (command line options) of this utility. Practice these, and once you&#8217;re done, head to the tool&#8217;s\u00a0<a href=\"https:\/\/linux.die.net\/man\/8\/ping\" target=\"_blank\" rel=\"noopener noreferrer\">man page<\/a> to know more about it.<\/p>\n<div>\n<p><b>Share this page:<\/b><\/p>\n<p>\n<a href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ping-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-3.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/intent\/tweet?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ping-command%2F&amp;text=Linux+ping+Command+Tutorial+for+Beginners+%288+Examples%29&amp;via=howtoforgecom&amp;related=howtoforgecom\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-4.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/twitter.com\/howtoforgecom\/\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-5.png\" height=\"20\" alt=\"\" title=\"\"><\/a><br \/>\n<a href=\"https:\/\/plus.google.com\/share?url=https%3A%2F%2Fwww.howtoforge.com%2Flinux-ping-command%2F\" target=\"_blank\" rel=\"nofollow noopener noreferrer\"><img decoding=\"async\" src=\"https:\/\/afaghhosting.net\/blog\/wp-content\/uploads\/2018\/06\/linux-ping-command-tutorial-for-beginners-8-examples-6.png\" height=\"20\" alt=\"\" title=\"\"><\/a>\n<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Regardless of the type of Linux user you are (beginner or pro), there are certain tools that you must be aware of. One such utility is Ping. In this tutorial, we will discuss the basics of this tool using some easy to understand examples. But before we do that, it&#8217;s worth mentioning that all examples [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-4800","post","type-post","status-publish","format-standard","hentry","category-36"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4800","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=4800"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/4800\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=4800"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=4800"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=4800"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}