Install netstat on Ubuntu
Learn to install the popular networking utility netstat on Ubuntu in this quick tutorial.
The netstat is one of the popular utilities that you can use to monitor the network on Ubuntu Linux but there's a catch.
When I tried the netstat command on my freshly installed Ubuntu server, it gave me an error saying "Command 'netstat' not found".
Also, when I used the "sudo apt install netstat" command, it didn't work either:
So how do you install the netstat comment on Ubuntu?
Well, that's pretty simple and can be installed using the following command:
sudo apt install net-tools
Want more details? I got you.
How to install netstat command on Ubuntu
As I mentioned earlier, you can not install the netstat command directly using the "sudo apt install netstat" command.
Want to know the reason? Well, that's pretty simple.
There is no package named netstat
exists in the Ubuntu repository. You need to install a different package called net-tools
to install the netstat utility.
In simple terms, you have to replace the netstat
with the net-tools
to install the netstat command in Ubuntu.
Here's what the end command would look like to install the netstat command in Ubuntu:
sudo apt install net-tools
Once done, you can check the installed version of the netstat utility using the following command:
netstat -V
As you can see, it gave me the netstat version 2.10.
Now, let's have a look at some basic examples of how you can use the netstat command.
How to use the netstat command in Ubuntu
Before I share some examples of the netstat command, let's have a look at the syntax of the netstat command:
netstat [options]
Pretty simple syntax. Right?
Here, the [options]
part is where you use the different flags to modify the default behaviour of the netstat command.
Now, let's have a look at some examples utilizing the multiple flags you are given with the netstat command.
1. Find all the listening ports
To list all the listening ports, all you have to do is use the -l
flag with the netstat command as shown:
netstat -l
2. List listening TCP ports
To list all the listening TCP ports, you have to pair the -l
flag with the -t
flag as shown here:
netstat -lt
3. List listening UDP ports
To list all the listening UDP ports, you have to use the -u
flag (for UDP ports) with the -l
flag as shown here:
netstat -lu
4. Get a statistical summary of each protocol
Want to know the number of messages sent and received, connections established, number of dropped packets, and more? You can do that by getting a summary of each protocol.
For this, all you have to do is use the -s
flag as shown:
netstat -s
5. Monitor the network continuously
Even I was not aware of this feature until I read the man page to learn more about the netstat utility.
To monitor the network continuously, you have to use the -c
flag:
netstat -c
There you have it!
More examples of the netstat command
While I shared some basic examples of the netstat command in this tutorial, you and do a lot more than this.
For that purpose, we wrote a detailed guide on how to use the netstat command with examples:
I hope you will find this guide helpful.
A software engineer who loves to tinker with hardware till it gets crashed. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.