Install netstat on Ubuntu
Installation

Install netstat on Ubuntu

Sagar Sharma
Sagar Sharma

Table of Contents

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:

E: Unable to locate package netstat

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
Check the installed version of Netstat command in Ubuntu

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
list all the listening ports using netstat command in Ubuntu Linux

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
List listening TCP ports using the netstat command in Ubuntu Linux

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
List listening UDP ports using the netstat command in Ubuntu Linux

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
Get a statistical summary of each protocol using the netstat command in Ubuntu Linux

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
Monitor network continously using the netstat command in Ubuntu Linux

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:

Netstat Command in Linux: 13 Practical Examples
Netstat is one of the most common networking commands in Linux. Learn some useful examples of netstat in this tutorial.

I hope you will find this guide helpful.



Sagar Sharma

Sagar Sharma

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.