bash: netstat: command not found – Debian/Ubuntu Linux

The netstat Linux command is used by system administrators to see information about network connections. Netstat is a powerful utility that can print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. It has been superseded by the ss command in recent years so you may get the “bash: netstat: command not found” error, but is still a viable tool for network diagnostics and troubleshooting.

The error bash: netstat: command not found will occur on up to date Ubuntu and Debian Linux systems when trying to execute the netstat command, as it is no longer included by default. In this tutorial, you will learn how to install the net-tools package on Ubuntu and Debian-based Linux systems, which provides access to the netstat command, among others.

In this tutorial you will learn:

  • How to install net-tools on Debian and Ubuntu
bash: netstat: command not found – Debian/Ubuntu Linux
bash: netstat: command not found – Debian/Ubuntu Linux
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu and Debian
Software net-tools
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

bash: netstat: command not found – Debian/Ubuntu Linux



DID YOU KNOW?
The ss command replaced the older netstat command on Linux. See our tutorial on Using ss command on Linux to see usage examples for the ss command and learn how it differs from netstat.

If you are looking for the netstat command and getting error:

bash: netstat: command not found

This simply means that the relevant package net-tools which includes netstat executable is not installed, thus missing. The package net-tools may not be installed on your system by default so you need to install it manually.

The package also includes aditional utilisties such as arp, ifconfig, netstat, rarp, nameif and route.

To make netstat available on your system simply install the net-tools package using the below command:

$ sudo apt update
$ sudo apt install net-tools

Using netstat command on Debian/Ubuntu Linux

Now that netstat is installed on your system, you can use some of the commands below to get started using it.

  1. First, let’s view the processes that are listening for connections. To do so so enter the following command.
    $ sudo netstat -tulpen
    



  2. Now let’s take a look at all of the current network connections. To do this enter the following command, which is similar to the previous one except that we use -a to view all sockets instead of -l to just view listening sockets.
    $ sudo netstat -atupen
    
  3. You may find yourself in a situation where you only want to view the ESTABLISHED connections. This is as easy as piping the output of netstat to grep like so.
    $ sudo netstat -atupen | grep ESTABLISHED
    
  4. The netstat’s -i option brings up a table listing all configured network interfaces on the system:
    $ sudo netstat -i
    

For more examples and tips on other networking tools, see our tutorials on How to monitor network activity on a Linux system and Learning Linux Commands: netstat.

Resolving the bash: netstat: command not found error on Debian/Ubuntu Linux
Resolving the bash: netstat: command not found error on Debian/Ubuntu Linux

Closing Thoughts




In this tutorial, we saw how to install the missing netstat command on an Ubuntu or other Debian based Linux system. We also learned some basic usage of the netstat command in order to get started using it. You will also want to look into the ss command, which supersedes netstat but has a separate syntax.