How to Install netstat on Debian 12

The netstat is the command line utility in Debian 12 that is used in network communication. It is extracted from the “Network Statistics” which means it provides the information of the networks connected to the computer. 

It is used to display all the network connections of the computer, provide information on the network statistics, and display the list of ports that are engaged in network communication. 

The netstat command is important to extract the information for troubleshooting the network issues and for new network connections. It can be used on Windows as well as UNIX-based Linux distributions. 

This post will explain the installation method of netstat on Debian 12 with the below-mentioned outline:

  1. How to Verify the Pre-Installation of netstat on Debian 12
  2. How to Install netstat on Debian 12
  3. What is the Basic Usage of netstat on Debian 12
  4. How to Uninstall the netstat on Debian 12
  5. What are the Alternatives of netstat on Debian 12

Let’s start the post by finding out the pre-installation of netstat on Debian 12. 

How to Verify the Pre-Installation of netstat on Debian 12?

Various Linux distributions come with the netstat command utility preinstalled on them. To verify that the netstat command utility is preinstalled on Debian 12 or not, run the command:

$ which netstat

If the output shows no outpur then it means the netstat command is not preinstalled. 

How to Install netstat on Debian 12?

To install the netstat command on Debian 12, follow the instructions explained in the next steps. 

Step 1: Launch the Terminal

Open the terminal of Debian 12 either by using the shortcut key of CTRL+ALT+T or from the application menu:

Step 2: Update all the Packages

When the terminal is launched, then update all the packages with the following command:

$ sudo apt update

Step 3: Install the netstat Command

For the installation of the netstat command in Debian 12, install the package of “net-tools” with the “install” option of the apt package manager:

$ sudo apt install net-tools -y

The netstat command is installed with the installation of the “net-tools” package. 

Step 4: Verify the Installation of the net-stat on Debian 12

To verify the installation, run the netstat command:

$ netstat

The output shows that netstat has been successfully installed on Debian 12. 

What is the Basic Usage of netstat on Debian 12?

The basic usage of the netstat on Debian 12 is explained with the below-mentioned commands. 

Example 1: Display all the Connections (Active)

To display all the active connections on Debian 12, simply run the netstat command:

$ netstat

Example 2: Display all the Listening Ports

To display the information of the services that are in the queue to connect with the ports, run the command:

$ netstat -l

Example 3: Display the Names of the Listening Ports

With reference to the previous example, to display the name of the services that are waiting for the incoming connections, run the command:

$ netstat -plnt

Example 4: Display the Statistics

To display the detailed statistics of the Networks, run the command:

$ netstat -s

Example 5: Display the Routing Tables

To display the information of the routing tables on Debian 12, run the netstat command with its “r” option:

$ netstat -r

Example 6: Display the UDP and TCP Connections

Display the UDP connections by using the “u” option and TCP connection with the “t” option of the netstat command:

$ netstat -u && netstat -t

All these examples explained the basic usage of the netstat command on Debian 12. 

How to Uninstall the netstat on Debian 12?

To uninstall the netstat command utility, remove the “net-tools” package with the command:

$ sudo apt remove net-tools -y

Also, remove the configuration files of the net-tools with the following command:

$ sudo apt purge net-tools -y

Finally, remove the unused dependencies of the net-tools package:

$ sudo apt autoremove -y

When the package of net-tools is completely removed from the Debian 12, then verify it by running the netstat command:

$ netstat

The package of the netstat command has successfully been removed from Debian 12. 

What are the Alternatives of netstat on Debian 12?

In the modern Linux distributions including the Debian 12, the netstat command has been replaced with the different commands. In Debian 12, users can use the “ip address” command or the “ss” command to find information about the network communication. 

Both these packages come preinstalled on Debian 12 but if they are unfortunately removed, they can still be installed running the command:

$ sudo apt install iproute2 -y

This is all about the installation of the netstat on Debian 12.

Conclusion

To install the netsat command on Debian 12, open the terminal and run the command “sudo apt install net-tools -y”. It is used to display the network’s information. This blog explained the installation of the netstat command utility with its basic usage on Debian 12. 

As it has been discussed that the netstat command is becoming obsolete in Debian 12 and other new releases of Linux distributions, some alternatives are also explained in this post.