How to Install netstat Command in Linux

Netstat – derived from the words network and statistics – is a command-line utility used by system administrators for analyzing network statistics.

It displays a whole manner of statistics such as open ports and corresponding addresses on the host system, routing table, and masquerade connections.

In this article, we will walk you through how you can install the netstat command in different Linux distributions.

How to Install netstat Command in Linux

The package that contains netstat is called net-tools. On modern systems, the netstat utility comes pre-installed and there’s no need to install it.

On older systems, however, you are likely to bump into an error when you run the netstat command.

bash: netstat: command not found

Therefore, to install netstat on Linux distributions, run the command.

$ sudo apt install net-tools         [On Debian, Ubuntu and Mint]
$ sudo yum install net-tools         [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
$ sudo emerge -a sys-apps/net-tools  [On Gentoo Linux]
$ sudo apk add net-tools            [On Alpine Linux]
$ sudo pacman -S net-tools           [On Arch Linux]
$ sudo zypper install net-tools      [On OpenSUSE]    

Once installed, run the command below to check the version of netstat installed.

# netstat -v

How to Use netstat Command in Linux

You can invoke the netstat command on any of the Linux distributions to get different statistics on your network.

1. Viewing the Network Routing Table

You use the -r flag to show the network routing table to get something similar to the output below.

# netstat -nr
List Network Routing Table
List Network Routing Table

The -n option forces netstat to print addresses separated by dots instead of using symbolic network names. The option is useful for avoiding address lookups over a network.

2. Display Network Interface Statistics

Use the -i flag to get an output of statistics of a network interface that is configured. The -a option prints all present interfaces in the kernel.

# netstat -ai
List Network Interface Statistics
List Network Interface Statistics

3. Show Network Connections

The netstat command utility supports options that display active or passive sockets using the options -t, -n, and -a. The flags show RAW, UDP, TCP, or UNIX connection sockets. Adding the -a option, it will sow sockets ready for connection.

# netstat -ant
List Network Connections
List Network Connections

4. Show Network Services

To list services, their current state, and their corresponding ports, run the command.

# netstat -pnltu
List Network Services
List Network Services

In this article, we shed light on how you can install the netstat command and how it is used to check a wide array of network statistics.

It’s also important to point out that netstat has been deprecated and instead, ss utility has taken its place in displaying more refined network statistics.

If you read this far, tweet to the author to show them you care. Tweet a thanks
James Kiarie
This is James, a certified Linux administrator and a tech enthusiast who loves keeping in touch with emerging trends in the tech world. When I'm not running commands on the terminal, I'm taking listening to some cool music. taking a casual stroll or watching a nice movie.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

3 thoughts on “How to Install netstat Command in Linux”

  1. I should point out that it is actually the most modern system that is likely to be missing netstat since ss is a newer replacement.

    Reply
  2. Arch Linux install is incorrect. “netstat-nat” is a different package that does not install the same.

    It should be:

    pacman -S net-tools
    
    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.