{"id":634,"date":"2010-02-09T11:42:43","date_gmt":"2010-02-09T09:42:43","guid":{"rendered":"http:\/\/www.netexpertise.eu\/en\/?p=634"},"modified":"2021-10-15T20:58:32","modified_gmt":"2021-10-15T18:58:32","slug":"network-stats-with-iptables","status":"publish","type":"post","link":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html","title":{"rendered":"Display Network Stats on Linux with Iptables"},"content":{"rendered":"\n<p>As for any firewall, <a href=\"\/en\/tag\/iptables\">iptables<\/a> is able to do network statistics reporting. the -v (&#8211;verbose) option along with the list switch (-L) show packets and bytes counters.<br>Network stats are available on a per rule basis. Here is an example on the INPUT chain:<br>&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[stats@linux_server]$ sudo iptables -nvL INPUT\nChain INPUT (policy DROP 74941 packets, 7900K bytes)\n<strong> pkts bytes<\/strong> target prot opt in out source    destination\n<strong>1392K  543M<\/strong> ACCEPT all  --  lo *   0.0.0.0\/0 0.0.0.0\/0\n<strong>1179K  680M<\/strong> ACCEPT all  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state RELATED,ESTABLISHED\n<strong>   10   524<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:22\n<strong>   25  1200<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:21\n<strong> 5372  260K<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:80\n<strong> 5842  280K<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:3306 \/* Mysql *\/\n<strong>   97  4536<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:9999 \/* APP *\/\n<strong>    0     0<\/strong> ACCEPT udp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   udp dpt:69 \/* TFTP *\/\n<strong>    0     0<\/strong> ACCEPT udp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   udp dpt:161 \/* SNMP requests *\/\n<strong>   73  4380<\/strong> ACCEPT icmp --  *  *   0.0.0.0\/0 0.0.0.0\/0   icmp type 8\n<\/code><\/pre>\n\n\n\n<p>&nbsp;<br>In this example, you could split the RELATED and ESTABLISHED state rule by port to get more detailed numbers.<br><br>There is no need to restart iptables to reset packet and byte counters, the built-in -Z or &#8211;zero flag makes it for you:<br>&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">[stats@linux_server]$ sudo iptables -Z INPUT\n[stats@linux_server]$ sudo iptables -nvL INPUT\nChain INPUT (policy DROP 74945 packets, 7901K bytes)\n<strong> pkts bytes<\/strong> target prot opt in out source    destination\n<strong>    0     0<\/strong> ACCEPT all  --  lo *   0.0.0.0\/0 0.0.0.0\/0\n<strong>    7   436<\/strong> ACCEPT all  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state RELATED,ESTABLISHED\n<strong>    0     0<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:22\n<strong>    0     0<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:21\n<strong>    0     0<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:80\n<strong>    0     0<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:3306 \/* Mysql *\/\n<strong>    0     0<\/strong> ACCEPT tcp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   state NEW tcp dpt:9999 \/* APP *\/\n<strong>    0     0<\/strong> ACCEPT udp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   udp dpt:69 \/* TFTP *\/\n<strong>    0     0<\/strong> ACCEPT udp  --  *  *   0.0.0.0\/0 0.0.0.0\/0   udp dpt:161 \/* SNMP requests *\/\n<strong>    0     0<\/strong> ACCEPT icmp --  *  *   0.0.0.0\/0 0.0.0.0\/0   icmp type 8\n<\/code><\/pre>\n\n\n\n<p>&nbsp;<br>On top of doing its firewall job and, even if you don&#8217;t make use of it, iptables may help you identify more precisely the root cause of network traffic congestion or simply get network stats of what&#8217;s going in and out of your servers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As for any firewall, iptables is able to do network statistics reporting. the -v (&#8211;verbose) option along with the list switch (-L) show packets and bytes counters.Network stats are available on a per rule basis. Here is an example on the INPUT chain:&nbsp; &nbsp;In this example, you could split the RELATED and ESTABLISHED state rule [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[11],"tags":[293,292,386,99],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netexpertise - Display Network Stats on Linux with Iptables<\/title>\n<meta name=\"description\" content=\"Display application and port network statistics with IPTables firewall on Linux Operating Systems\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netexpertise - Display Network Stats on Linux with Iptables\" \/>\n<meta property=\"og:description\" content=\"Display application and port network statistics with IPTables firewall on Linux Operating Systems\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html\" \/>\n<meta property=\"og:site_name\" content=\"Netexpertise\" \/>\n<meta property=\"article:published_time\" content=\"2010-02-09T09:42:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-10-15T18:58:32+00:00\" \/>\n<meta name=\"author\" content=\"dave\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@netexpertise\" \/>\n<meta name=\"twitter:site\" content=\"@netexpertise\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html\",\"name\":\"Netexpertise - Display Network Stats on Linux with Iptables\",\"isPartOf\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\"},\"datePublished\":\"2010-02-09T09:42:43+00:00\",\"dateModified\":\"2021-10-15T18:58:32+00:00\",\"author\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\"},\"description\":\"Display application and port network statistics with IPTables firewall on Linux Operating Systems\",\"breadcrumb\":{\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"http:\/\/www.netexpertise.eu\/en\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Display Network Stats on Linux with Iptables\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#website\",\"url\":\"http:\/\/www.netexpertise.eu\/en\/\",\"name\":\"Netexpertise\",\"description\":\"Systems \/ Networks \/ DevOps\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa\",\"name\":\"dave\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"contentUrl\":\"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g\",\"caption\":\"dave\"},\"sameAs\":[\"http:\/\/www.netexpertise.eu\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netexpertise - Display Network Stats on Linux with Iptables","description":"Display application and port network statistics with IPTables firewall on Linux Operating Systems","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html","og_locale":"en_US","og_type":"article","og_title":"Netexpertise - Display Network Stats on Linux with Iptables","og_description":"Display application and port network statistics with IPTables firewall on Linux Operating Systems","og_url":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html","og_site_name":"Netexpertise","article_published_time":"2010-02-09T09:42:43+00:00","article_modified_time":"2021-10-15T18:58:32+00:00","author":"dave","twitter_card":"summary_large_image","twitter_creator":"@netexpertise","twitter_site":"@netexpertise","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html","url":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html","name":"Netexpertise - Display Network Stats on Linux with Iptables","isPartOf":{"@id":"http:\/\/www.netexpertise.eu\/en\/#website"},"datePublished":"2010-02-09T09:42:43+00:00","dateModified":"2021-10-15T18:58:32+00:00","author":{"@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa"},"description":"Display application and port network statistics with IPTables firewall on Linux Operating Systems","breadcrumb":{"@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.netexpertise.eu\/en\/systems\/linux\/network-stats-with-iptables.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"http:\/\/www.netexpertise.eu\/en"},{"@type":"ListItem","position":2,"name":"Display Network Stats on Linux with Iptables"}]},{"@type":"WebSite","@id":"http:\/\/www.netexpertise.eu\/en\/#website","url":"http:\/\/www.netexpertise.eu\/en\/","name":"Netexpertise","description":"Systems \/ Networks \/ DevOps","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.netexpertise.eu\/en\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/cb4cd666549d22e9070ec1cfc1a496fa","name":"dave","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.netexpertise.eu\/en\/#\/schema\/person\/image\/","url":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","contentUrl":"http:\/\/1.gravatar.com\/avatar\/1129916e1f4955bd632f27f836f64e55?s=96&d=mm&r=g","caption":"dave"},"sameAs":["http:\/\/www.netexpertise.eu"]}]}},"_links":{"self":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/634"}],"collection":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/comments?post=634"}],"version-history":[{"count":0,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/posts\/634\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/media?parent=634"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/categories?post=634"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.netexpertise.eu\/en\/wp-json\/wp\/v2\/tags?post=634"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}