Linux – netstat command .

This tutorial comes to show you how to use the netstat command with the Linux operating system.
To list out all the connections TCP, UDP & Unix on a system, we can use ‘a’ option with netstat command:

To list only the TCP connections our system, use ‘t’ options with netstat:

To list out only the UDP connections on our system, we can use ‘u’ option with netstat:

To only list out Unix socket connections, we can use ‘x’ options:

To get a list of all connections along with PID or process name, we can use ‘p’ option & it can be used in combination with any other netstat option:

To speed up our output, we can use ‘n’ option as it will perform any reverse lookup & produce output with only numbers (since no lookup is performed, our output will much faster):

To print only the listening ports, we will use ‘l’ option with netstat (it will not be used with ‘a’ as it prints all ports):

To print network statistics of each protocol like packet received or transmitted, we can use ‘s’ options with netstat:

To display only the statistics on network interfaces, use ‘i’ option:

To display multicast group information, we can use option ‘g’ ( that print the multicast group information for IPV4 & IPV6):

To print the network routing information, use ‘r’ option:

To get the continuous output of netstat, use ‘c’ option:

To filter a single port connection, we can combine ‘grep’ command with netstat:

To use multiple commands with netstat.
Example: count the number of connections with CONNECTED value, we can further add ‘wc’ command with netstat and grep command:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.