When trying to run netstat, you get the error shown in the screenshot below.
The net-tools collection, which includes the netstat utility, was deprecated and replaced with iproute2. The current network utility collection Iproute2 replaces netstat with the ss command. Some net-tools replacements can be found in the table below.
Solution: Installing netstat on Debian 11
Installing netstat on Debian and its distributions is as simple as installing other packages using the apt command. Just run the command below to get the net-tools collection installed.
Now you are able to run netstat, as shown in the screenshot below.
As you can see, netstat works now.
Understanding the netstat output:
The example above where netstat was executed without flags returned the following 6 columns:
- Proto: This column specifies the connection protocol.
- Recv-Q: This column displays the data retained in the receiving queue.
- Send-Q: This column displays the data retained in the outbound queue.
- Local Address: Our local host or IP address and the used port.
- Foreign Address: The remote host or IP address we are connected to.
- State: The connection state.
To make this tutorial complete, I also decided to add netstat instructions below.
How to use the netstat command:
After installing netstat on Debian 11, this section shows some netstat command use examples.
In the previous example, when netstat was executed without flags, it returned, among other columns, Foreign Address, which includes host addresses. By implementing the -n flag as shown in the next screenshot, you can instruct netstat to return only numerical foreign addresses.
As you can see now, the output shows the IP of remote devices instead of their hostnames.
The following example shows how to display only TCP connections by adding the -t flag.
As you can see, only TCP connections were printed. Contrary to the previous example, if you want to print UDP connections, replace the -t flag with -u, as shown in the next example.
Running netstat with the -p flag, you will see a new column named PID/Program name. Under this column, you can see the processes or programs establishing connections.
As you can see in the last column, there are PIDs and programs (chrome) behind the connections.
If followed by the -a flag, the netstat command will return all sockets, both listening and no listening.
The -s flag is used to print summary statistics for each protocol, as shown in the screenshot below.
You also can combine the -t and -s flags to show statistics on TCP connections only, as shown in the example below.
And you can combine the -s flag with -u for statistics on UDP connections, as shown below.
The netstat command can also print the route table by adding the -r flag, shown in the following screenshot.
Finally, to end this tutorial, you can print IPv6 information using the -g flag, as shown in the image below.
netstat (netstat) vs ss (socketstat):
The netstat command is considered obsolete and was deprecated and replaced by the ss command. The ss command is faster and consumes fewer resources than netstat. The ss command is faster than netstat because it reads information directly from the kernel. When netstat checks every PID under /proc, ss directly acquires the statistics information under /pro/net. It is highly recommended that Linux users adopt the new alternative (ss) over netstat and the same for all other tools included in iproute2.
As you could realize by reading this tutorial, installing netstat on Debian 11 is pretty easy. It doesn’t work on default new Linux installations because it isn’t included in the net-tools packages collection. Despite this tutorial answering how to make netstat work on Debian 11 and new distributions, using the ss command instead is the correct choice. There are no netstat functionalities that weren’t included in ss. Yet many users keep using the old netstat just because they are used to ( like the ifconfig command). By adding the net-tools package whose installation was explained in this tutorial, you’ll also get classic commands like ifconfig, route, or arp.
Thank you for reading this tutorial explaining how to install netstat on Debian 11. Keep following us for more Linux tips and tutorials.