netstat

Netstat Command in Linux

Netstat is a command-line tool used by system administrators to evaluate network configuration and activity. The term Netstat is results from network and statistics. It shows open ports on the host device and their corresponding addresses, the routing table, and masquerade connections.

The purpose of this post is to show you how to install and configure different Netstat commands in Linux.

Installing Net-tools on Linux:

Netstat is part of a package named net-tools. You can get the net-tools package on Ubuntu with the command:

$ sudo apt install net-tools

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image1 final.png

Check Version of Netstat:

Upon installation, check the installed version of Netstat:

$ netstat –v

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image3 final.png

Netstat command in Linux:

Display Routing table:

Netstat command shows the routing table detail on the terminal. If you wish to see the routing table, use the –nr flag with Netstat; it shows the kernel routing table in the same way that route does. Use the below command:

$ netstat -nr

Instead of using symbolic address names, the -nr option allows Netstat to print addresses divided by dots

Display interface statistics:

Using the ‘-i’ flag or option with Netstat will show statistics for the currently configured network interfaces.

$ netstat -i

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image5 final.png

If the “–a” flag is also used with “-i”, the command prints all of the kernel interfaces.

$ netstat -ai

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image4 final.png

Display Network connection:

To view active or passive sockets, Netstat has a range of options. Active TCP, UDP, RAW, and Unix socket connections are specified by the –t, –u, –w, and –x options, respectively.

Type on your terminal:

$ netstat -ta

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image7 final.png

Display Network Services:

Run the following command to see a list of networks, their current states, and their associated ports:

$ netstat -pnltu

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image6 final.png

Display all the listening port of TCP and UDP connection:

You can see all TCP and UDP ports by using the command:

$ netstat –a | more

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image8 fial.png

Display TCP Port Connection:

To get the list of only TCP (Transmission Control Protocols) port connection, use the following command:

$ netstat -at

Display UDP Port Connection:

To see UDP (User Diagrams Protocols) port connection, use the command:

$ netstat -au

Display all Listening Connection:

List all the active connection by using the “-l” flag with Netstat:

$ netstat -l

Display all TCP Listening port:

We can get the list of all active listening TCP ports by using the –‘lt’ flag as follows:

$ netstat -lt

Display all UDP listening port:

We can get the list of all active listening UDP ports by using ‘–lu’ option:

$ netstat -lu

Display all Unix Listening port:

Display the list of all active listening UNIX ports by using –lx:

$ netstat -lx

Showing Statistics by Protocol:

Displays protocol-specific statistics. The TCP, UDP, ICMP, and IP protocol statistics are displayed by default. A set of protocols can be defined using the -s option:

$ netstat -s

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image15 final.png

Showing Statistics by TCP Protocol:

Display the list of only TCP protocols by using the ‘–st’ option with Netstat:

$ netstat -st

Showing Statistics by UDP Protocol

Display the list of only UDP protocols by using the ‘–su’ option with Netstat:

$ netstat -su

D:\Aqsa\Nestat Command in Linux\Nestat Command in Linux\images\image17 final.png

Conclusion:

Netstat is a valuable method for tracking network activity and configuration. It is, in reality, a jumbled-up collection of several resources. In this post, we have demonstrated that how to manage network connections using the Netstat command.

About the author

Avatar

Aqsa Maqbool

As a Software engineer, I am passionate to write about various IT related
articles but have deep interest in Linux. I spend most of my time reading Linux related blogs and IT related books. I want to serve the world with my writing skills.