<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Think Lamp &#187; ping</title>
	<atom:link href="http://www.think-lamp.com/tag/ping/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.think-lamp.com</link>
	<description>Everything Linux Apache Php Mysql</description>
	<lastBuildDate>Fri, 18 Feb 2011 01:28:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
		<item>
		<title>The (hidden) power of &#8216;ping&#8217;</title>
		<link>http://www.think-lamp.com/2009/03/the-hidden-power-of-ping/</link>
		<comments>http://www.think-lamp.com/2009/03/the-hidden-power-of-ping/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 23:50:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[computer]]></category>
		<category><![CDATA[LAN]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://www.think-lamp.com/?p=108</guid>
		<description><![CDATA[PING Ping is a Unix utility that sends ICMP ECHO to the server ( destination machine ) from the client ( originating machine ). It takes its name from a submarine sonar search &#8211; you send a short sound burst and listen for an echo &#8211; a ping &#8211; coming back. There is a myth <a href='http://www.think-lamp.com/2009/03/the-hidden-power-of-ping/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1 style="text-align: center;"><span style="color: #000000;">PING</span></h1>
<p><img class="aligncenter size-medium wp-image-109" title="echo" src="http://www.think-lamp.com/wp-content/uploads/2008/11/echo-300x178.jpg" alt="" width="300" height="178" /></p>
<p><strong>Ping </strong>is a Unix utility that sends ICMP ECHO to the server ( destination machine )  from the client ( originating machine ). It takes its name from a submarine sonar search &#8211; you send a short sound burst and listen for an echo &#8211; a <em>ping</em> &#8211; coming back. There is a myth that  Ping is actually an acronym for the words &#8216;Packet INternet Groper&#8217;, but there is no proven evidence to support the statement.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-3741710014597097";
/* 468x15, created 3/25/09 */
google_ad_slot = "1110499399";
google_ad_width = 468;
google_ad_height = 15;
// --></script><br />
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"></script></p>
<p><span id="more-108"></span></p>
<p>For years, system admins, managers, developers, and the-next-door-jack have been using this utility, primarily to check if the <strong><em>&#8216;target system is alive&#8217;</em></strong><em><strong>. </strong></em>Ping, is thus undercredited by deeming it as an utility which has only one function.  &#8220;<span style="color: #333300;"><em><strong>Type in ping &lt;target_machine&gt; , if it gives response the machine is UP, if it doesn&#8217;t either machine is down OR network is down.</strong> </em></span>&#8220;NOT NECESSARILY TRUE!</p>
<h3><strong>What (other) Information can a  &#8216;ping&#8217; give you ? </strong></h3>
<ol>
<li> If the &lt;target_machine&gt; is alive  [ there are cases where this doesn't work ]</li>
<li>How long each packet exchange took</li>
<li>Interframe Gap</li>
<li>Reports other ICMP messages that might otherwise get buried in the system software</li>
<li>Exponential Moving Average</li>
<li>How occupied is the target system including the network that routes from host to the target.</li>
</ol>
<p>Now, how &#8216;you&#8217;  use this information to draw conclusions and metrics, is upon you. I&#8217;ll show some examples in the later part of this article.</p>
<p><em><strong>Lets see a sample Ping Output</strong></em></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">-bash-<span style="color: #000000;">3.00</span>$ <span style="color: #c20cb9; font-weight: bold;">ping</span> www.google.com
PING www.l.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.104<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000;">56</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">84</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> bytes of data.
<span style="color: #000000;">64</span> bytes from yo-in-f104.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.104<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">0</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">246</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">7.97</span> ms
<span style="color: #000000;">64</span> bytes from yo-in-f104.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.104<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">1</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">246</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">13.7</span> ms
<span style="color: #000000;">64</span> bytes from yo-in-f104.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.104<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">2</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">246</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">9.69</span> ms
<span style="color: #000000;">64</span> bytes from yo-in-f104.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.104<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">3</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">246</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">8.15</span> ms
&nbsp;
<span style="color: #660033;">---</span> www.l.google.com <span style="color: #c20cb9; font-weight: bold;">ping</span> statistics <span style="color: #660033;">---</span>
<span style="color: #000000;">4</span> packets transmitted, <span style="color: #000000;">4</span> received, <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span> packet loss
rtt min<span style="color: #000000; font-weight: bold;">/</span>avg<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>mdev = <span style="color: #000000;">7.971</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">9.884</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">13.716</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2.313</span> ms</pre></div></div>

<p>pretty normal eh ! Whats so new in that ?<br />
Now, I can bet 50% of people who read this may not know the significance of all the digits or abbreviations in the output. It is a good idea to have a detailed knowledge of it in order to understand what is actually happening.<br />
This will also help you to change the data in order to detect certain problems.</p>
<p><strong>1.</strong> When you ping www.google.com it replies www.l.google.com which is actually a CNAME in the DNS database.<br />
<strong>2.</strong> The second line has the IP address of the host that is found. This IP address is found from the DNS query to the DNS database. ( I will be writing an article about how the DNS query actually works ! Watch out for it )<br />
<strong>3.</strong> Line two has two numbers (56 and 84 ) as bytes of data while all the reply has another (64) bytes of data. Now what are these ?</p>
<p>PING is an ICMP Packet with  20 bytes of IP header + 8 bytes ICMP header  + XX byes of data ( or call it the payload )</p>
<p>IN default case, the whole frame is set to 64 bytes That is 20 IP header + 8 ICMP header + 56 bytes of payload. That is how you get all these numbers .. never thought of it isn&#8217;t it ?</p>
<div class="wp-caption aligncenter" style="width: 522px"><img title="ICMP Packet" src="http://www.caida.org/tools/measurement/skitter/packets/skitter_ttl_out_pkt.gif" alt="image reference : www.caida.org" width="512" height="309" /><p class="wp-caption-text">image reference : www.caida.org</p></div>
<p><strong>4. </strong>The next four lines show the successful reply from the IP address and their reverse DNS host names. See how the host names actually differ in all the first three lines of the output  ? That is the magic of DNS and load balancing, which I will be discussing in a n separate article.</p>
<p><strong>5.</strong> These also have 3 major things: (a) icmp_seq  (b)ttl and (c)time in miliseconds</p>
<p><strong>(a) icmp_seq </strong>number is the sequence number of packets that are transmitted and received back by the client. If a sequence number is missing OR if there is a gap in the sequence number that means that the client is sending more than what the server can take. It is called source quench. As ICMP is a lower level protocol it can only detect errors not correct it ( as IP or TCP does ).</p>
<h3><em><strong>how to  simulate source quench ? </strong></em></h3>
<div id="attachment_140" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.think-lamp.com/wp-content/uploads/2009/03/echo_point.jpg"><img class="size-medium wp-image-140" title="Echo " src="http://www.think-lamp.com/wp-content/uploads/2009/03/echo_point-300x204.jpg" alt="Image Courtesy: www.cartoonstock.com" width="300" height="204" /></a><p class="wp-caption-text">Image Courtesy: www.cartoonstock.com</p></div>
<p>You can use the command -i0 :this switch will set interval to 0 , this means that the client will continuously keep on sending packets without waiting for a response from the server. This will result in server getting busy and thus dropping packets.<br />
You can also use the switch -s500 : this switch will set the payload along with ICMP header size to 500 and the server has to accept and process more data from the server ( A ping with packet larger than 64 is called <strong><span style="text-decoration: underline;">The Ping of Death</span></strong> )<br />
You can use both at the same time to get good results</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-i0</span> <span style="color: #660033;">-s500</span> www.google.com</pre></div></div>

<p><span style="text-decoration: underline;">Lets see an output:</span></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">64</span> bytes from host232.hostmonster.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>74.220.215.232<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">24</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">50</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">114</span> ms
<span style="color: #000000;">64</span> bytes from host232.hostmonster.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>74.220.215.232<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">25</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">50</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">123</span> ms
<span style="color: #000000;">64</span> bytes from host232.hostmonster.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>74.220.215.232<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">27</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">50</span> <span style="color: #007800;"><span style="color: #000000; font-weight: bold;">time</span></span>=<span style="color: #000000;">112</span> ms</pre></div></div>

<p>Here we see that the icmp sequence number 26 is lost. This indicates that the server is busy and thus cannot accept data at these throughputs.<strong> <span style="color: #993300;">Now, in production environment something like this can be used to  compare  past &#8216;good&#8217; results to a problem scenario. If all of a sudden you find that there is a large packet drop on the ping with the normal 64 byte 0 second interval packets, you can judge that there could be something wrong with the either devices OR the network pipe OR the internet connection itself could be slow. Comparing these figures on a different server / different network  / different subnet would help you determine the problem area, and in some cases you can actually pinpoint the culprit. </span></strong></p>
<p><strong>(b) TTL</strong></p>
<p>Any IP packet that gets sent out will have a TTL field which normally is set to a relatively high number (in the case of ping the default  TTL is 255). As the packet traverses the network, the TTL field gets decreased by one by each HOP ( or router ) it goes through; when the TTL drops to 0, the packet is discarded by the router. The IP specification says that the TTL should be set to 60 (though it&#8217;s 255 for ping packets). The main purpose of this is so that a packet doesn&#8217;t live forever on the network and will eventually die when it is deemed &#8220;lost.&#8221; But for ping purposes, it provides additional information. The TTL can be used to determine approximately how many router hops the packet has gone through. If the TTL field varies in successive pings, it could indicate that the successive reply packets are going via different routes, which isn&#8217;t a great thing.</p>
<p>So a TTL of 245 for gogole.com means that it took (255-245 = ) 10 hops to reach google.com server.<br />
<strong><span style="color: #993300;">On a production environment, in a ping output a low TTL means that it took the packet higher number of hops to reach to the destination. Time to check your network routing table ?</span></strong></p>
<p><strong>(c) time</strong></p>
<p>The time is the time in milliseconds (ms) that it took to reach to the source and back. <span style="color: #993300;"><span style="color: #000000;">Thus it is also called RTT or the Round Trip Time</span>.</span><strong><span style="color: #993300;"> In a production environment a HIGH  RTT suggests that there is a congestion in the network. </span></strong></p>
<p><strong>6.</strong> After the ping terminates ( normally ctrl+c  OR with a switch -c&lt;#&gt; where &lt;#&gt; is the count before termination ) you will see number of packets transmitted, number failed and the percentage failed. In this example output its a 100% success but In the above source quench example we can see the number of packets failed and the percentage non zero.</p>
<p><strong>7.</strong> The min/avg/max/mdev is the  minimum / average / maximum / standard deviation of the round trip times. To have a good number and analysis, send at least  50 to 100 packets.</p>
<h3><strong>What else ?</strong></h3>
<p style="text-align: center;"><a href="http://www.think-lamp.com/wp-content/uploads/2009/03/english_echo.jpg"><img class="size-medium wp-image-141 aligncenter" title="Give something get something" src="http://www.think-lamp.com/wp-content/uploads/2009/03/english_echo.jpg" alt="" width="300" height="300" /></a></p>
<p>Lets take a look at the end of the output:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">64</span> bytes from yo-in-f99.google.com <span style="color: #7a0874; font-weight: bold;">&#40;</span>64.233.169.99<span style="color: #7a0874; font-weight: bold;">&#41;</span>: <span style="color: #007800;">icmp_seq</span>=<span style="color: #000000;">29</span> <span style="color: #007800;">ttl</span>=<span style="color: #000000;">245</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>truncated<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #660033;">---</span> www.l.google.com <span style="color: #c20cb9; font-weight: bold;">ping</span> statistics <span style="color: #660033;">---</span>
<span style="color: #000000;">30</span> packets transmitted, <span style="color: #000000;">30</span> received, <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span> packet loss, <span style="color: #000000; font-weight: bold;">time</span> 540ms
rtt min<span style="color: #000000; font-weight: bold;">/</span>avg<span style="color: #000000; font-weight: bold;">/</span>max<span style="color: #000000; font-weight: bold;">/</span>mdev = <span style="color: #000000;">7.560</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">7.996</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">8.609</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">0.257</span> ms,  ipg<span style="color: #000000; font-weight: bold;">/</span>ewma <span style="color: #000000;">18.632</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">7.945</span> ms</pre></div></div>

<p>Focus on the line: ipg/ewma . That is: inter-packet gap / exponential moving average.</p>
<p><strong>InterPacket Gap (measured in seconds)</strong></p>
<p>The Inter-packet gap (or the inter-frame gap) is an idle time period appended to the end of every frame by the ethernet adapter. This idle time gives the network media a chance to stabilize, and other network components time to process the frame. On specifying the i0 or the -f switch in ping we can get the output resulting ping statistics which gives the current ipg of the system.<br />
The minimum interframe gap is 96 bit times (the time it takes to transmit 96 bits of raw data on the medium), which is<br />
9.6 μs for 10 Mbit/s Ethernet,<br />
960 ns for 100 Mbit/s (fast) Ethernet,<br />
96 ns for 1 Gbit/s (gigabit) Ethernet, and<br />
9.6 ns for 10 Gbit/s (10 gigabit) Ethernet.<br />
This is the minimum gap as specified in Ethernet protocol and required for a non-colliding transmission. There are ways to reduce it for a faster UDP transmissions, but can cause heavy collisions if other devices ( client and server ) aren&#8217;t able to handle the high rate of transmission.</p>
<p>In ideal situations for a 10 Mbps line and 9.6 μs of IFG the loss is 14.28%</p>
<p style="text-align: center;"><a href="http://www.think-lamp.com/wp-content/uploads/2009/03/ifg_calc.gif"><img class="size-medium wp-image-143 aligncenter" title="ifg calculations" src="http://www.think-lamp.com/wp-content/uploads/2009/03/ifg_calc.gif" alt="" width="300" height="286" /></a></p>
<p style="text-align: left;"><strong><span style="color: #993300;">Now, once you have the ifg and your Ethernet pipe speed. You can easily determine the network efficiency.</span></strong></p>
<p><strong>Exponential Weighted Moving Average (measured in seconds)</strong></p>
<p>Estimated packet rate is used to identify abnormal activities and attacks. The ethernet adapter estimates the arrival of the next packet based on the information of previous packet. If the packet time is more it will go to sleep (saving power).<br />
Although I want to I cannot talk a lot about EWMA as it is beyond the scope of this article, but on a <strong><span style="color: #993300;">production system  A quick look at the rtt and ewma will tell you if something is wrong. rtt ~ ewma  for regular case. </span></strong></p>
<p>During operations, the effective idletime is measured using an exponential weighted moving average (EWMA), which considers recent packets to be exponentially more important than past ones. The Unix loadaverage is calculated in the same way.<br />
The calculated idle time is subtracted from the EWMA measured one, the resulting number is called &#8216;avgidle&#8217;. A perfectly loaded link has an avgidle of zero: packets arrive exactly at the calculated interval.</p>
<p><span style="font-family: Courier New;"><small></small></span></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.think-lamp.com%2F2009%2F03%2Fthe-hidden-power-of-ping%2F&amp;linkname=The%20%28hidden%29%20power%20of%20%26%238216%3Bping%26%238217%3B"><img src="http://www.think-lamp.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://www.think-lamp.com/2009/03/the-hidden-power-of-ping/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

