{"id":1191,"date":"2009-12-18T04:41:14","date_gmt":"2009-12-18T09:41:14","guid":{"rendered":"http:\/\/g33kinfo.com\/info\/?p=1191"},"modified":"2009-12-18T04:41:14","modified_gmt":"2009-12-18T09:41:14","slug":"using-netstat","status":"publish","type":"post","link":"https:\/\/g33kinfo.com\/info\/using-netstat\/","title":{"rendered":"Using netstat"},"content":{"rendered":"<p>From cyberciti.biz<br \/>\nThe netstat command and pipe feature can be used to dig out information about a particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat.<\/p>\n<p>This is useful to find out if your server is under attack or not. You can also list abusive IP address using this method.<br \/>\n<code><br \/>\n# netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n<br \/>\n<\/code><br \/>\nOutput:<br \/>\n<code><br \/>\n      1 CLOSE_WAIT<br \/>\n      1 established)<br \/>\n      1 Foreign<br \/>\n      3 FIN_WAIT1<br \/>\n      3 LAST_ACK<br \/>\n     13 ESTABLISHED<br \/>\n     17 LISTEN<br \/>\n    154 FIN_WAIT2<br \/>\n    327 TIME_WAIT<br \/>\n<\/code><br \/>\nDig out more information about a specific ip address:<br \/>\n<code>netstat -nat |grep {IP-address} | awk '{print $6}' | sort | uniq -c | sort -n<\/p>\n<p>      2 LAST_ACK<br \/>\n      2 LISTEN<br \/>\n      4 FIN_WAIT1<br \/>\n     14 ESTABLISHED<br \/>\n     91 TIME_WAIT<br \/>\n    130 FIN_WAIT2<br \/>\n<\/code><br \/>\nBusy server can give out more information:<br \/>\n<code>netstat -nat |grep 202.54.1.10 | awk '{print $6}' | sort | uniq -c | sort -n<br \/>\nOutput:<\/p>\n<p>  15 CLOSE_WAIT<br \/>\n  37 LAST_ACK<br \/>\n  64 FIN_WAIT_1<br \/>\n  65 FIN_WAIT_2<br \/>\n1251 TIME_WAIT<br \/>\n3597 SYN_SENT<br \/>\n5124 ESTABLISHED<br \/>\n<\/code><br \/>\nGet List Of All Unique IP Address<\/p>\n<p>To print list of all unique IP address connected to server, enter:<br \/>\n<code>netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '\/^$\/d' | uniq<\/code><br \/>\nTo print total of all unique IP address, enter:<br \/>\n<code>netstat -nat | awk '{ print $5}' | cut -d: -f1 | sed -e '\/^$\/d' | uniq | wc -l<br \/>\nOutput:<\/p>\n<p>449<br \/>\n<\/code><\/p>\n<p>Find Out If Box is Under DoS Attack or Not<\/p>\n<p>If you think your Linux box is under attack, print out a list of open connections on your box and sorts them by according to IP address, enter:<br \/>\n<code><br \/>\nnetstat -atun | awk '{print $5}' | cut -d: -f1 | sed -e '\/^$\/d' |sort | uniq -c | sort -n<br \/>\nOutput:<\/p>\n<p>    1 10.0.77.52<br \/>\n      2 10.1.11.3<br \/>\n      4 12.109.42.21<br \/>\n      6 12.191.136.3<br \/>\n.....<br \/>\n...<br \/>\n....<br \/>\n    13 202.155.209.202<br \/>\n     18 208.67.222.222<br \/>\n     28 0.0.0.0<br \/>\n    233 127.0.0.1<br \/>\n<\/code><\/p>\n<p>You can simply block all abusive IPs using iptables or just null route them.<\/p>\n<p>Get Live View of TCP Connections<\/p>\n<p>You can use tcptrack command to display the status of TCP connections that it sees on a given network interface. tcptrack monitors their state and displays information such as state, source\/destination addresses and bandwidth usage in a sorted, updated list very much like the top command.<br \/>\nDisplay Summary Statistics for Each Protocol<\/p>\n<p>Simply use netstat -s:<br \/>\n<code><br \/>\nnetstat -s | less<br \/>\nnetstat -t -s | less<br \/>\nnetstat -u -s | less<br \/>\nnetstat -w -s | less<br \/>\nnetstat -s<br \/>\nOutput:<\/p>\n<p>Ip:<br \/>\n    88354557 total packets received<br \/>\n    0 forwarded<br \/>\n    0 incoming packets discarded<br \/>\n    88104061 incoming packets delivered<br \/>\n    96037391 requests sent out<br \/>\n    13 outgoing packets dropped<br \/>\n    66 fragments dropped after timeout<br \/>\n    295 reassemblies required<br \/>\n    106 packets reassembled ok<br \/>\n    66 packet reassembles failed<br \/>\n    34 fragments failed<br \/>\nIcmp:<br \/>\n    18108 ICMP messages received<br \/>\n    58 input ICMP message failed.<br \/>\n    ICMP input histogram:<br \/>\n        destination unreachable: 7173<br \/>\n        timeout in transit: 472<br \/>\n        redirects: 353<br \/>\n        echo requests: 10096<br \/>\n    28977 ICMP messages sent<br \/>\n    0 ICMP messages failed<br \/>\n    ICMP output histogram:<br \/>\n        destination unreachable: 18881<br \/>\n        echo replies: 10096<br \/>\nTcp:<br \/>\n    1202226 active connections openings<br \/>\n    2706802 passive connection openings<br \/>\n    7394 failed connection attempts<br \/>\n    47018 connection resets received<br \/>\n    23 connections established<br \/>\n    87975383 segments received<br \/>\n    95235730 segments send out<br \/>\n    681174 segments retransmited<br \/>\n    2044 bad segments received.<br \/>\n    80805 resets sent<br \/>\nUdp:<br \/>\n    92689 packets received<br \/>\n    14611 packets to unknown port received.<br \/>\n    0 packet receive errors<br \/>\n    96755 packets sent<br \/>\nTcpExt:<br \/>\n    48452 invalid SYN cookies received<br \/>\n    7357 resets received for embryonic SYN_RECV sockets<br \/>\n    43 ICMP packets dropped because they were out-of-window<br \/>\n    5 ICMP packets dropped because socket was locked<br \/>\n    2672073 TCP sockets finished time wait in fast timer<br \/>\n    441 time wait sockets recycled by time stamp<br \/>\n    368562 delayed acks sent<br \/>\n    430 delayed acks further delayed because of locked socket<br \/>\n    Quick ack mode was activated 36127 times<br \/>\n    32318597 packets directly queued to recvmsg prequeue.<br \/>\n    741479256 packets directly received from backlog<br \/>\n    1502338990 packets directly received from prequeue<br \/>\n    18343750 packets header predicted<br \/>\n    10220683 packets header predicted and directly queued to user<br \/>\n    17516622 acknowledgments not containing data received<br \/>\n    36549771 predicted acknowledgments<br \/>\n    102672 times recovered from packet loss due to fast retransmit<br \/>\n    Detected reordering 1596 times using reno fast retransmit<br \/>\n    Detected reordering 1 times using time stamp<br \/>\n    8 congestion windows fully recovered<br \/>\n    32 congestion windows partially recovered using Hoe heuristic<br \/>\n    19 congestion windows recovered after partial ack<br \/>\n    0 TCP data loss events<br \/>\n    39951 timeouts after reno fast retransmit<br \/>\n    29653 timeouts in loss state<br \/>\n    197005 fast retransmits<br \/>\n    186937 retransmits in slow start<br \/>\n    131433 other TCP timeouts<br \/>\n    TCPRenoRecoveryFail: 20217<br \/>\n    147 times receiver scheduled too late for direct processing<br \/>\n    29010 connections reset due to unexpected data<br \/>\n    365 connections reset due to early user close<br \/>\n    6979 connections aborted due to timeout<br \/>\n<\/code><\/p>\n<p>Display Interface Table<\/p>\n<p>You can easily display dropped and total transmitted packets with netstat for eth0:<br \/>\n<code>netstat --interfaces eth0<br \/>\nOutput:<\/p>\n<p>Kernel Interface table<br \/>\nIface       MTU Met    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg<br \/>\neth0       1500   0  2040929      0      0      0  3850539      0      0      0 BMRU<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>From cyberciti.biz The netstat command and pipe feature can be used to dig out information about a particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat. This is useful to find out if&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/g33kinfo.com\/info\/using-netstat\/\">Read More<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-1191","post","type-post","status-publish","format-standard","hentry","category-info"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Using netstat - Linux Shtuff<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/g33kinfo.com\/info\/using-netstat\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using netstat - Linux Shtuff\" \/>\n<meta property=\"og:description\" content=\"From cyberciti.biz The netstat command and pipe feature can be used to dig out information about a particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat. This is useful to find out if... Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/g33kinfo.com\/info\/using-netstat\/\" \/>\n<meta property=\"og:site_name\" content=\"Linux Shtuff\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:author\" content=\"https:\/\/fb.me\/g33kinf0\" \/>\n<meta property=\"article:published_time\" content=\"2009-12-18T09:41:14+00:00\" \/>\n<meta name=\"author\" content=\"g33kadmin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/drsinger1111\" \/>\n<meta name=\"twitter:site\" content=\"@drsinger1111\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/\"},\"author\":{\"name\":\"g33kadmin\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"headline\":\"Using netstat\",\"datePublished\":\"2009-12-18T09:41:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/\"},\"wordCount\":251,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"articleSection\":[\"General Info\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/\",\"name\":\"Using netstat - Linux Shtuff\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\"},\"datePublished\":\"2009-12-18T09:41:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/using-netstat\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Using netstat\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#website\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/\",\"name\":\"Linux Shtuff\",\"description\":\"Because I have CRS Syndrome...\",\"publisher\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/#\\\/schema\\\/person\\\/c022e4c40b13ea1b678e6f020756f547\",\"name\":\"g33kadmin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"url\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"contentUrl\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\",\"width\":512,\"height\":512,\"caption\":\"g33kadmin\"},\"logo\":{\"@id\":\"https:\\\/\\\/g33kinfo.com\\\/info\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/minion-researchA.gif\"},\"description\":\"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\\\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....\",\"sameAs\":[\"https:\\\/\\\/thelinuxreport.com\",\"https:\\\/\\\/fb.me\\\/g33kinf0\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/drsinger1111\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using netstat - Linux Shtuff","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":"https:\/\/g33kinfo.com\/info\/using-netstat\/","og_locale":"en_US","og_type":"article","og_title":"Using netstat - Linux Shtuff","og_description":"From cyberciti.biz The netstat command and pipe feature can be used to dig out information about a particular IP address connection. You can find out total established connections, closing connection, SYN and FIN bits and much more. You can also display summary statistics for each protocol using netstat. This is useful to find out if... Read More","og_url":"https:\/\/g33kinfo.com\/info\/using-netstat\/","og_site_name":"Linux Shtuff","article_publisher":"https:\/\/fb.me\/g33kinf0","article_author":"https:\/\/fb.me\/g33kinf0","article_published_time":"2009-12-18T09:41:14+00:00","author":"g33kadmin","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/drsinger1111","twitter_site":"@drsinger1111","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/#article","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/"},"author":{"name":"g33kadmin","@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"headline":"Using netstat","datePublished":"2009-12-18T09:41:14+00:00","mainEntityOfPage":{"@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/"},"wordCount":251,"commentCount":0,"publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"articleSection":["General Info"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/g33kinfo.com\/info\/using-netstat\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/","url":"https:\/\/g33kinfo.com\/info\/using-netstat\/","name":"Using netstat - Linux Shtuff","isPartOf":{"@id":"https:\/\/g33kinfo.com\/info\/#website"},"datePublished":"2009-12-18T09:41:14+00:00","breadcrumb":{"@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/g33kinfo.com\/info\/using-netstat\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/g33kinfo.com\/info\/using-netstat\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/g33kinfo.com\/info\/"},{"@type":"ListItem","position":2,"name":"Using netstat"}]},{"@type":"WebSite","@id":"https:\/\/g33kinfo.com\/info\/#website","url":"https:\/\/g33kinfo.com\/info\/","name":"Linux Shtuff","description":"Because I have CRS Syndrome...","publisher":{"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/g33kinfo.com\/info\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/g33kinfo.com\/info\/#\/schema\/person\/c022e4c40b13ea1b678e6f020756f547","name":"g33kadmin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","url":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","contentUrl":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif","width":512,"height":512,"caption":"g33kadmin"},"logo":{"@id":"https:\/\/g33kinfo.com\/info\/wp-content\/uploads\/2022\/07\/minion-researchA.gif"},"description":"I am a g33k, Linux blogger, developer, student and Tech Writer for Liquidweb.com\/kb. My passion for all things tech drives my hunt for all the coolz. I often need a vacation after I get back from vacation....","sameAs":["https:\/\/thelinuxreport.com","https:\/\/fb.me\/g33kinf0","https:\/\/x.com\/https:\/\/twitter.com\/drsinger1111"]}]}},"_links":{"self":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/1191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/comments?post=1191"}],"version-history":[{"count":0,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/posts\/1191\/revisions"}],"wp:attachment":[{"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/media?parent=1191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/categories?post=1191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g33kinfo.com\/info\/wp-json\/wp\/v2\/tags?post=1191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}