{"id":11313,"date":"2021-10-29T10:12:19","date_gmt":"2021-10-29T10:12:19","guid":{"rendered":"https:\/\/linuxways.net\/?p=11313"},"modified":"2021-10-29T10:12:19","modified_gmt":"2021-10-29T10:12:19","slug":"monitor-network-traffic-using-netstat-command-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/centos\/monitor-network-traffic-using-netstat-command-in-linux\/","title":{"rendered":"Monitor Network Traffic Using netstat Command in Linux"},"content":{"rendered":"<p><strong>Netstat<\/strong> stands for <strong>Network statistics<\/strong>. This is a command-line tool used to show intensive deep information about how your system is communicating with other network devices or remote machines. Netstat command specifically displays the details of all individual network connections, protocol-oriented and overall statistics of the computer network. Using the netstat utility, you can easily troubleshoot your network problems. Netstat utility is a cross-platform command-line tool that is available for almost all Windows versions, Linux OS, and Mac operating systems.<\/p>\n<p>This article will provide the complete details about the usage of the netstat command. You will also learn how users can monitor network traffic using the <a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/netstat\">netstat<\/a> command-line utility.<\/p>\n<h2><strong>Installation of Netstat command-line tool<\/strong><\/h2>\n<p>To use the netstat utility, you need to install net-tools on your Linux system using the following command:<\/p>\n<p>For Ubuntu \/ Debian operating distribution<\/p>\n<pre>$ sudo apt install net-tools<\/pre>\n<p>For CentOS 8 and Fedora distribution<\/p>\n<pre>$ sudo dnf install net-tools<\/pre>\n<h2><strong>How to use the Netstat command to monitor network traffic?<\/strong><\/h2>\n<p>The following syntax generally is used to run the netstat command:<\/p>\n<pre>Netstat {options}<\/pre>\n<p>Now, explain the working of each option with the help of some examples:<\/p>\n<h3><strong>List all connections and ports<\/strong><\/h3>\n<p>To display the report of all active, established, and listening TCP, UDP connections use the following netstat command along with the option -i.<\/p>\n<pre>$ netstat \u2013i<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"622\" class=\"wp-image-11314\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-386.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-386.png 912w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-386-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-386-768x524.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/p>\n<h3><strong>List all TCP \/ UDP Ports only<\/strong><\/h3>\n<p>To list all TCP ports run the below-mentioned command:<\/p>\n<pre>$ netstat -at<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"916\" height=\"672\" class=\"wp-image-11315\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-387.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-387.png 916w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-387-300x220.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-387-768x563.png 768w\" sizes=\"auto, (max-width: 916px) 100vw, 916px\" \/><\/p>\n<p>Similarly, to list only all UDP ports, use the following command:<\/p>\n<pre>$ netstat -au<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"909\" height=\"254\" class=\"wp-image-11316\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-388.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-388.png 909w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-388-300x84.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-388-768x215.png 768w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/p>\n<h3><strong>List all TCP \/ UDP \/ UNIX listening ports<\/strong><\/h3>\n<p>Use the following command to display all listening TCP ports:<\/p>\n<pre>$ netstat -lt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"236\" class=\"wp-image-11317\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-389.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-389.png 910w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-389-300x78.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-389-768x199.png 768w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\" \/><\/p>\n<p>To display all listening UDP ports, run the following command:<\/p>\n<pre>$ netstat -lu<\/pre>\n<p>To list all UNIX listening ports use the command as follows:<\/p>\n<pre>$ netstat -lx<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"349\" class=\"wp-image-11318\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-390.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-390.png 921w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-390-300x114.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-390-768x291.png 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/p>\n<h3><strong>List statistics of all TCP \/ UDP ports<\/strong><\/h3>\n<p>The \u2018-s\u2019 option is to specifically print the statistics of your overall network. However, you can specifically display the statistics of TCP and UDP ports by using the following command:<\/p>\n<pre>$ netstat -stu<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"911\" height=\"623\" class=\"wp-image-11319\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-391.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-391.png 911w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-391-300x205.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-391-768x525.png 768w\" sizes=\"auto, (max-width: 911px) 100vw, 911px\" \/><\/p>\n<h3><strong>List network interfaces transactions<\/strong><\/h3>\n<p>To list all MTU transferring and receiving packets information in the kernel interface table, use the below-mentioned command:<\/p>\n<pre>$ netstat \u2013i<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"905\" height=\"175\" class=\"wp-image-11320\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-392.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-392.png 905w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-392-300x58.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-392-768x149.png 768w\" sizes=\"auto, (max-width: 905px) 100vw, 905px\" \/><\/p>\n<p>To display a more extended kernel interface table information use the command which is given below:<\/p>\n<pre>$ netstat -ie<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"921\" height=\"482\" class=\"wp-image-11321\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-393.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-393.png 921w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-393-300x157.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-393-768x402.png 768w\" sizes=\"auto, (max-width: 921px) 100vw, 921px\" \/><\/p>\n<h3><strong>List summary of listening processes<\/strong><\/h3>\n<p>By combining different netstat options, you can do a more advanced search about listening connections as follows:<\/p>\n<pre>$ sudo netstat \u2013tulpen<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"909\" height=\"589\" class=\"wp-image-11322\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-394.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-394.png 909w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-394-300x194.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-394-768x498.png 768w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/p>\n<p>t &#8211; Shows TCP connections<\/p>\n<p>u &#8211; Shows UDP connections<\/p>\n<p>l &#8211; Displays all listening connections<\/p>\n<p>p &#8211; Shows the program name to which the listed connection belongs<\/p>\n<p>e &#8211; Displays the extended information<\/p>\n<p>n &#8211; Displays the users, addresses, and ports numerically.<\/p>\n<p>Similarly, if you want to display all sockets instead of display only the listening sockets replace the \u2018-l\u2019 option with \u2018-l\u2019 in the above-mentioned command:<\/p>\n<pre>$ netstat -atupen<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"915\" height=\"607\" class=\"wp-image-11323\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-395.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-395.png 915w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-395-300x199.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-395-768x509.png 768w\" sizes=\"auto, (max-width: 915px) 100vw, 915px\" \/><\/p>\n<p>To only list the established connections from the above output, you can use the grep command for piping the output as follows:<\/p>\n<pre>$ sudo netstat -atupen | grep ESTABLISHED<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"442\" class=\"wp-image-11324\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-396.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-396.png 908w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-396-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-396-768x374.png 768w\" sizes=\"auto, (max-width: 908px) 100vw, 908px\" \/><\/p>\n<h3><strong>Display network details continuously<\/strong><\/h3>\n<p>To display the network information continuously after each second, use the below-mentioned command:<\/p>\n<pre>$ netstat -c<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"911\" height=\"640\" class=\"wp-image-11325\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-397.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-397.png 911w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-397-300x211.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-397-768x540.png 768w\" sizes=\"auto, (max-width: 911px) 100vw, 911px\" \/><\/p>\n<p>To print all listening TCP connections continuously, use the command, which is given below:<\/p>\n<pre>$ netstat -clt<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"906\" height=\"440\" class=\"wp-image-11326\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-398.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-398.png 906w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-398-300x146.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-398-768x373.png 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/p>\n<p>Using \u2018Ctrl+c\u2019 to exit from continues output display.<\/p>\n<p>To view all unconfigured addresses, use the following command:<\/p>\n<pre>$ netstat --verbose<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"909\" height=\"148\" class=\"wp-image-11327\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-399.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-399.png 909w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-399-300x49.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-399-768x125.png 768w\" sizes=\"auto, (max-width: 909px) 100vw, 909px\" \/><\/p>\n<p>You can also list a process that uses the specific port for example list programs using port 80.<\/p>\n<pre>$ netstat -an | grep ':80'<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"911\" height=\"99\" class=\"wp-image-11328\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-400.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-400.png 911w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-400-300x33.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-400-768x83.png 768w\" sizes=\"auto, (max-width: 911px) 100vw, 911px\" \/><\/p>\n<p>To get more help related to netstat options and their usage, use the following command:<\/p>\n<pre>$ netstat -h<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"912\" height=\"643\" class=\"wp-image-11329\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-401.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-401.png 912w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-401-300x212.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/10\/word-image-401-768x541.png 768w\" sizes=\"auto, (max-width: 912px) 100vw, 912px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>We have seen how to monitor network traffic using the <a href=\"https:\/\/docs.oracle.com\/cd\/E19504-01\/802-5753\/6i9g71m3i\/index.html\">netstat command<\/a>. We explored the uses of the netstat command on the Linux system. In this article, we learned different netstat options that provide help to find the desired results<strong>.\u00a0<\/strong><\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>Netstat stands for Network statistics. This is a command-line tool used to show intensive deep information about how your system is communicating with other network devices or remote&hellip;<\/p>","protected":false},"author":1,"featured_media":11683,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,4,5,83,165,2],"tags":[35,641],"class_list":["post-11313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-debian","category-mint","category-opensuse","category-red-hat","category-ubuntu","tag-linux","tag-netstat-command"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=11313"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/11313\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/11683"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=11313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=11313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=11313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}