{"id":224,"date":"2020-06-20T00:09:34","date_gmt":"2020-06-19T16:09:34","guid":{"rendered":"https:\/\/byy3.com\/?p=224"},"modified":"2021-03-26T05:41:02","modified_gmt":"2021-03-25T21:41:02","slug":"linux-ping-command","status":"publish","type":"post","link":"https:\/\/byy3.com\/?p=224","title":{"rendered":"linux ping command"},"content":{"rendered":"\r\n<figure class=\"wp-block-image\"><img decoding=\"async\" class=\"wp-image-747\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/the-linux-ping-command-1024x512.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe\" alt=\"linux ping command\u63d2\u56fe\" \/><\/figure>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Ping or Packet Internet Groper is a network administration utility used to check the connectivity status between a source and a destination computer\/device over an IP network. It also helps you assess the time it takes to send and receive a response from the network.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">We all have our favorite websites that we frequently visit; if any of these does not load, we really want to know why it happened. Is it because we don\u2019t have an internet connection or is it the issues with our internet service provider preventing us from accessing the website. Another reason might be the unavailability of the website itself. No matter what the reason, the Linux Ping command can provide you with all the answers.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Ping uses the ICMP(Internet Control Message Protocol) to send and receive echo messages from and to the host and destination computers respectively to tell us about the performance of the network. An ICMP request message is sent to the destination computer; if the destination IP address is available, it sends an ICMP message response to the host computer. This tells us about the connectivity status of the network such as round-trip time-the time taken to send and receive a packet of information.<\/p>\r\n<p>\u52aa\u529b\u627e\u4e86\u534a\u5929\uff0c\u5728\u4e00\u7bc7\u6587\u7ae0\u7684\u5b57\u91cc\u884c\u95f4\u53d1\u73b0\u4e86 ping \u7684\u6765\u5386\uff5e\u00a0<\/p>\r\n<p>root@node2:\/# <strong>apt-get install inetutils-ping<\/strong><\/p>\r\n<p>\u8fd8\u6709ifconfig \u00a0 \u53ef\u4ee5\u7528<strong> apt-get install net-tools<\/strong> \u6765\u5b89\u88c5\uff5e\u00a0<\/p>\r\n<p><strong>\u6216\u8005fping\u00a0 <\/strong><\/p>\r\n<p><strong>fping 192.168.0.1 192.168.0.125 192.168.0.126 2&gt;\/dev\/null<\/strong><\/p>\r\n<p>fping -g 192.168.1.0\/24 2&gt;\/dev\/null<\/p>\r\n<hr \/>\r\n<h1 id=\"articleContentId\" class=\"title-article\">tcping\u66ff\u4ee3ping\u6765\u9a8c\u8bc1\u670d\u52a1\u5668\u662f\u5426\u8fd0\u884c\u6b63\u5e38<\/h1>\r\n<p>\u4f7f\u7528tcping<\/p>\r\n<p>$ tcping<br \/>error: Usage: tcping [-q] [-t timeout_sec] [-u timeout_usec] &lt;host&gt; &lt;port&gt;<\/p>\r\n<p>$ tcping -t 3 www.baidu.com 80<\/p>\r\n<p>$ echo $?<\/p>\r\n<p>\u6839\u636e$?\u7684\u8fd4\u56de\u503c, README\u91cc\u9762\u6709\u8be6\u7ec6\u7684\u8bf4\u660e\uff1a<\/p>\r\n<p>Return values to the shell are:<br \/>-1 \u00a0 \u00a0 \u00a0an error occured<br \/>0 \u00a0 \u00a0 \u00a0 port is open<br \/>1 \u00a0 \u00a0 \u00a0 port is closed<br \/>2 \u00a0 \u00a0 \u00a0 connection establishment timed out<br \/>\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Using the Ping command<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In the Linux terminal type the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">ping<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">This is the output you will get:<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-676\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-27.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe1\" alt=\"linux ping command\u63d2\u56fe1\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Let us describe(in alphabetic order) the commonly used options that you can see above:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-table\">\r\n<table>\r\n<tbody>\r\n<tr>\r\n<td><strong>Option<\/strong><\/td>\r\n<td><strong>Description<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>a<\/td>\r\n<td>Use this option for a beep sound when the peer is reachable<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>b<\/td>\r\n<td>Use this option to allow pinging a broadcast address<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>B<\/td>\r\n<td>Use this option if you do not want to allow the ping to change the source address of the probe<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>c (count)<\/td>\r\n<td>Use this option to set the number of times to send the ping request<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>d<\/td>\r\n<td>Use this option to set the SO-DEBUG option on the socket being used<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>f<\/td>\r\n<td>Use this option to flood the network by sending hundred or more packets per second<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>i (interval)<\/td>\r\n<td>Use this option to specify an interval between successive packet transmissions. The default value of interval is 1 second<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>I (interface address)<\/td>\r\n<td>Use this option to set source address to the specified interface address. This option is required when pinging IPv6 link local address. Its argument can be an IP address or name of the device.<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>l (preload)<\/td>\r\n<td>Use this option to set the number of packets to send without waiting for a reply. For selecting a value more than 3, you need to be a super user.<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>n<\/td>\r\n<td>Use this option to display network addresses as numbers rather than as hostnames<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>q<\/td>\r\n<td>Use this option to display a quiet output. It means that only the summary is displayed at startup and finish time<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>T (ttl)<\/td>\r\n<td>Use this option to set the Time To Live<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>v<\/td>\r\n<td>Use this option for verbose output<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>V<\/td>\r\n<td>Use this option to display the version and exit<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>w (deadline)<\/td>\r\n<td>Use this option to specify a timeout, in seconds, before ping exits, regardless of how many packets have been sent or received.<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>W (timeout)<\/td>\r\n<td>Use this option to set the time(seconds) to wait for a response<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Some Basic Ping functions<\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here are some basic ping functions that you will be using to check the performance of your network:<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Pinging the host for availability<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can check if a host is alive or not through the following ping command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping host-name\/IP<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Press Ctrl+C for breaking the command<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-677\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-28.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe2\" alt=\"linux ping command\u63d2\u56fe2\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Increase\/Decrease interval between ping packets<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The default time interval between sending each packet is 1 second in Linux. You can increase the time interval by setting a value greater than 1 and decrease it by setting a value less than 1.<\/p>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here is an example to increase the time interval between two pings:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -i 5 127.0.0.1<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here is an example to decrease the time interval between two pings:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -i 0.5 127.0.0.1<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">As you can see in the following image, you need to be a super user in order to set this time interval lesser than 0.2 seconds:<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-678\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-29.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe3\" alt=\"linux ping command\u63d2\u56fe3\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Therefore, the command should be executed with sudo. It should look like the following,<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\"><em>\u00a0$ sudo ping -i 0.5 127.0.0.1<\/em><\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Enter the password when you are prompted and the command should work.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Change ping packet size<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The default ping packet size is 56 bytes. You can change it through the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -s packetsize hostname\/IP<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here we are setting the packet size to 100; you can see the value set to 100 in the first line of output:<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-679\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-30.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe4\" alt=\"linux ping command\u63d2\u56fe4\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Set ping to send a desired number of packets<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can set ping to send a desired number of packets as follows:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -c NumberOfPackets IP\/hostname<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">In the following example we are setting the number of packets as 5; after that, the results will end:<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-680\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-31.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe5\" alt=\"linux ping command\u63d2\u56fe5\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Flooding the network<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Ping command allows super users to send 100 or more packets per second through the following command:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ sudo ping -f hostname-IP<\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\"><img loading=\"lazy\" decoding=\"async\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-32.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" srcset=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-32.png 689w, https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-32-300x59.png 300w\" width=\"689\" height=\"135\" title=\"linux ping command\u63d2\u56fe6\" alt=\"linux ping command\u63d2\u56fe6\" \/><\/h2>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Ping prints a \u201c.\u201d when sending a ping and \u201c\/\u201d when receiving one.<\/p>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Set ping timeout<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">You can set a time limit after which ping will exit; no matter how many ping packets are sent or received:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -w timeinseconds hostname\/ip<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Here we are using 3 seconds as timeout:<\/p>\r\n\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter\"><img decoding=\"async\" class=\"wp-image-682\" data-original=\"https:\/\/vitux.com\/wp-content\/uploads\/2018\/07\/word-image-33.png\" src=\"https:\/\/byy3.com\/wp-content\/themes\/MNews%20V2.4\/images\/post-loading.gif\" title=\"linux ping command\u63d2\u56fe7\" alt=\"linux ping command\u63d2\u56fe7\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Audible ping<\/h3>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">The ping command can be set to play a beep to check whether the host is available as follows:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-preformatted\">$ ping -a hostname\/ip<\/pre>\r\n\r\n\r\n\r\n<p class=\"wp-block-paragraph\">Practicing around with this tutorial will enable you to run ping commands to check your network performance in an optimal way. You can also use advance switches to customize your requests and responses in ping.<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Ping or Packet Internet Groper is a network administrat [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,1],"tags":[593,592,591,353,445,589,590],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-linux","category-net-security","tag-ifconfig","tag-linuxifconfig","tag-linuxping","tag-linux","tag-ping","tag-ping-command"],"_links":{"self":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224"}],"version-history":[{"count":0,"href":"https:\/\/byy3.com\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions"}],"wp:attachment":[{"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/byy3.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}