The Linux OS offers several command-line utilities to get statistics on different aspects of the system. One of the best legacy command-line utilities to view the network stats is “netstat”. The “netstat” is short for “Network Statistics”. It displays the live snapshot of active connections, open ports, routing tables, and much more.

The “netstat” command is pre-installed on older Debian-based operating systems, but in Debian 12 it is an optional utility and not pre-installed. 

Since the “netstat” command is now depreciated, this guide explains the process of installing it on Debian 12 and explores its alternatives.

Let’s begin!

How to Install the “netstat” Utility on Debian 12

The “netstat” command comes bundled in the “net-tools” package. To install the “netstat” utility, use the below-stated command to install it:

sudo apt install net-tools

To verify the installation of the “netstat” utility on Debian 12, use the following command:

netstat -V

If the output of the above command is “bash: /usr/bin/netstat: No such file or directory” or “netstat: Command not found”; it means that the “net-tools” command is not installed.

How to Use the “netstat” Utility on Debian 12

Let’s view the flags of the “netstat” utility before understanding it via the examples. To view a list of flags/options of the “netstat”, run:

netstat -h

Let’s understand the above flags using the examples.

Example 1: View All Active and Listening Sockets

To view a list of all active and listening sockets on Debian 12 using the “netstat” command, execute the below command:

netstat -a

The above output shows,

  • The “Proto” or “Protocol” tells which protocol is being used by the socket.
  • The “Recv-Q” shows the number of queued bytes waiting to be received.
  • The “Send-Q” shows the number of queued bytes waiting to be sent.
  • The “Local Address” displays the local IP address.
  • The “Foreign Address” displays the IP address of the remote system that is connected to the current system.
  • The “State” defines the state of the port.

Example 2: View Only TCP Connections

To get a list of the active connections that use the “TCP”, use the following command:

netstat -t

The above output is empty because there is no active TCP connection.

To get a list of “Listening TCP Connections”, use:

netstat -at

Example 3: View Only UDP Connections

To output the list of connections that use the “UDP”, use the below command:

netstat -u

To list the “Active Connections” that use the “UDP”, execute:

netstat -au

Example 4: View IP Addresses Without Resolving Hostnames

The “Resolve Hostname” points to the process that associates the hostnames with the IP addresses. To view the IP addresses without resolving the hostname, run:

netstat -n

Example 5: List Programs Associated With the Connections

To list the programs or applications along with their path and PID associated with the connections, use:

netstat -p

Example 6: View the Kernel IP Routing Table

The “Kernel IP Routing Table” is the map using which the router determines how to forward the packages. To view it, use the following command:

netstat -r

Example 6: View the Statistics of the Configured Interfaces

The “Kernel Interface table” refers to the currently configured network interfaces. To view the list and statistics of the currently configured network interfaces, execute the following command:

netstat -i

Alternatives for the “netstat” Utility on Debian 12

Since the “netstat” utility is officially depreciated, there are some alternatives that display more refined and informative network statistics. The alternatives for the “netstat” utility on Debian 12, include the following:

The “ss” Command

Linux being the open-source OS allows the developer community to build more user-friendly utilities. One such utility is the “ss” command. The “ss” command lets you view the network statistics in a more sophisticated way than the “netstat” command. It comes pre-installed on Debian 12; however, if it is not, install it via the below command:

sudo apt install iproute2

The syntax of using the “ss” command is as follows:

ss [OPTIONS]
ss [OPTIONS] [FILTER]

To list options and understand their usage, use the following command:

ss -h

The “iftop” Command

To monitor the network traffic more effectively, the “iftop” command introduces itself as the replacement for the “netstat” command. It is not pre-installed on Debian 12. To install the “iftop” command on Debian 12, execute the below-mentioned command:

sudo apt install iftop

The syntax of the “iftop” command is as follows:

sudo iftop [OPTIONS]

To get a list of options, run the below-stated command:

sudo iftop -h

Note: The “iftop” command runs with “sudo” privileges and gives the error “iftop: command not found” if run without “sudo”.

The “tcpdump” Command

With the recent developments in the world of Linux, the “tcpdump” command emerged as the replacement for the “netstat” command. It captures and analyzes the network packets, which provide valuable information for network administrators to fix the issues in the network.

The “tcpdump” command is not pre-installed on Debian 12. To install it, use the following mentioned command:

sudo apt install tcpdump

The syntax of the “tcpdump” command is as follows:

tcpdump [OPTIONS]

To explore the options/flags for the “tcpdump” command, use:

tcpdump -h

Note: The “tcpdump” command requires “sudo” privileges to run.

That’s all about installing the “netstat” command on Debian 12.

Final Words

The “netstat” command is a legacy command-line utility that allows network administrators to analyze active connections, ports, and much more. To install it on newer Debian-based distributions, install the “net-tools” package.

The “netstat” is now officially depreciated and is no longer maintained or developed. However, the Linux developers propose using the “ss”, “iftop” and “tcpdump” commands to analyze the network with more efficiency. This guide has discussed installing and using the “netstat” command on Debian 12 and shed light on its alternatives as well.