title: Is it possible to count number of ICMP packets sent/received per interface in Linux?
body: <p>Is it possible to check statistics in Linux per interface for ICMP packets in particular? <strong>ifconfig</strong> command it provides statistics per interface for received and sent packets:</p>
  
  <pre><code>-&gt; /sbin/ifconfig eth1
  eth1      Link encap:Ethernet  HWaddr BC:30:5B:ED:DE:54  
            UP BROADCAST RUNNING SLAVE MULTICAST  MTU:1500  Metric:1
            RX packets:412327300 errors:0 dropped:0 overruns:0 frame:0
            TX packets:765211747 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:327931865613 (312740.1 Mb)  TX bytes:803392590272 (766174.8 Mb)
            Memory:dcc00000-dcd00000 
  </code></pre>
  
  <p>But what I am looking for, is some specific type of packets (like ICMP) per interface.</p>
  
  <p>Also Linux is providing those statistics but globally in <strong>/proc/net/snmp</strong>:</p>
  
  <pre><code>-&gt; cat /proc/net/snmp
  ... log truncated ...
  Icmp: InMsgs InErrors InDestUnreachs InTimeExcds InParmProbs InSrcQuenchs InRedirects InEchos InEchoReps InTimestamps InTimestampReps InAddrMasks InAddrMaskReps OutMsgs OutErrors OutDestUnreachs OutTimeExcds OutParmProbs OutSrcQuenchs OutRedirects OutEchos OutEchoReps OutTimestamps OutTimestampReps OutAddrMasks OutAddrMaskReps
  Icmp: 29697 5 276 9 0 0 0 29409 3 0 0 0 0 29970 0 561 0 0 0 0 5 29404 0 0 0 0
  IcmpMsg: InType0 InType3 InType8 InType11 OutType0 OutType3 OutType8
  IcmpMsg: 3 276 29409 9 29404 561 5
  ... log truncated ...
  </code></pre>
  
  <p>Or more pretty printing in with <strong>netstat -s</strong> command (-s stands for statistics of course):</p>
  
  <pre><code>-&gt; netstat -s
  ... log truncated ...
  Icmp:
      29697 ICMP messages received
      5 input ICMP message failed.
      ICMP input histogram:
          destination unreachable: 276
          timeout in transit: 9
          echo requests: 29409
          echo replies: 3
      29970 ICMP messages sent
      0 ICMP messages failed
      ICMP output histogram:
          destination unreachable: 561
          echo request: 5
          echo replies: 29404
  IcmpMsg:
          InType0: 3
          InType3: 276
          InType8: 29409
          InType11: 9
          OutType0: 29404
          OutType3: 561
          OutType8: 5
  ... log truncated ...
  </code></pre>
  
  <p>So, the question is. is there any way to get ICMP statistics for some specific interface instead of global ICMP statistics for the whole system in Linux?</p>