How To Install Netstat On Linux – Network Statistics Setup Method

Monitoring network connections on Linux requires Netstat to be installed from the net-tools package. If you’re wondering how to install netstat on linux, you’ve come to the right place. Netstat is a powerful command-line utility that displays network connections, routing tables, interface statistics, and more. Many modern Linux distributions no longer include it by default, favoring newer tools like ss. But for those who prefer the classic netstat syntax, installation is straightforward.

This guide walks you through the entire process, from checking if netstat is already installed to installing it on major distributions like Ubuntu, Debian, CentOS, Fedora, and Arch Linux. We’ll also cover common troubleshooting tips and alternatives. Let’s get started.

What Is Netstat And Why Install It?

Netstat (network statistics) is a command that shows active network connections, listening ports, and network protocol statistics. It’s been a staple for system administrators and developers for decades.

Even though newer tools like ss are faster and more feature-rich, netstat remains popular because of its familiar output and widespread documentation. Many scripts and tutorials still reference netstat, making it essential for compatibility.

Installing netstat gives you a reliable way to diagnose network issues, check for open ports, and monitor connections without learning new syntax.

How To Install Netstat On Linux

Before installing, check if netstat is already on your system. Open a terminal and type:

netstat -v

If you see version information, netstat is already installed. If you get a “command not found” error, proceed with the installation steps below.

Check Your Linux Distribution

Different distributions use different package managers. Identify your distribution with:

cat /etc/os-release

Or use:

lsb_release -a

Once you know your distribution, follow the appropriate section.

Install Netstat On Ubuntu And Debian

Ubuntu and Debian use the apt package manager. Netstat is part of the net-tools package.

  1. Update your package list:
sudo apt update
  1. Install net-tools:
sudo apt install net-tools -y

After installation, verify with:

netstat -v

You should see version details. Now you can use netstat commands like netstat -tuln to list listening ports.

Install Netstat On CentOS, RHEL, And Fedora

For CentOS and RHEL 7/8, use yum or dnf. Fedora uses dnf.

CentOS/RHEL 7:

sudo yum install net-tools -y

CentOS/RHEL 8 and Fedora:

sudo dnf install net-tools -y

Verify installation:

netstat -v

If you get an error, ensure EPEL repository is enabled on CentOS/RHEL:

sudo yum install epel-release -y

Then retry the install.

Install Netstat On Arch Linux And Manjaro

Arch-based distributions use pacman. Net-tools is available in the official repositories.

sudo pacman -S net-tools

Confirm with:

netstat -v

Manjaro users can use the same command.

Install Netstat On OpenSUSE

OpenSUSE uses zypper. Install net-tools with:

sudo zypper install net-tools

Verify after installation.

Install Netstat On Alpine Linux

Alpine uses apk. Install net-tools:

sudo apk add net-tools

Alpine is minimal, so net-tools might not be pre-installed.

Common Installation Issues And Fixes

Sometimes installation doesn’t go smoothly. Here are typical problems and solutions.

Package Not Found

If your package manager says “package not found,” update your repositories first:

  • Debian/Ubuntu: sudo apt update
  • CentOS/RHEL: sudo yum update
  • Fedora: sudo dnf update

If still missing, check if the repository is enabled. On CentOS, EPEL is often required.

Permission Denied

Netstat requires root privileges for some options. Always use sudo when installing or running commands like netstat -tuln.

Netstat Command Still Not Found

After installation, if the command isn’t found, try logging out and back in, or run:

hash -r

This refreshes the command hash table.

Conflicting Packages

Some systems have both net-tools and iproute2. They can coexist, but if you get conflicts, remove the conflicting package first:

sudo apt remove iproute2

Then install net-tools. Be cautious, as iproute2 is the modern standard.

How To Use Netstat After Installation

Once installed, you can start monitoring network connections. Here are essential commands.

List All Listening Ports

sudo netstat -tuln

This shows TCP and UDP ports in listening state, with numeric addresses.

Show All Active Connections

sudo netstat -a

Displays all sockets, including listening and non-listening.

Display Routing Table

netstat -r

Shows the kernel routing table.

Show Network Interface Statistics

netstat -i

Lists network interfaces and packet statistics.

Continuous Monitoring

sudo netstat -c

Refreshes every second, similar to watch netstat.

Netstat Alternatives: When To Use Ss Or Other Tools

While netstat is reliable, modern Linux systems recommend ss (socket statistics) from the iproute2 package. ss is faster and provides more detailed information.

To use ss instead:

  • ss -tuln shows listening ports
  • ss -a shows all connections

If you prefer netstat’s output, you can alias it:

alias netstat='ss -tuln'

But for compatibility, keeping net-tools installed is fine.

Uninstalling Netstat

If you no longer need netstat, remove it:

  • Debian/Ubuntu: sudo apt remove net-tools
  • CentOS/RHEL: sudo yum remove net-tools
  • Fedora: sudo dnf remove net-tools
  • Arch: sudo pacman -R net-tools

This frees up space and reduces package bloat.

Frequently Asked Questions

Is Netstat Installed By Default On Linux?

No, most modern distributions do not include netstat by default. You need to install the net-tools package.

Can I Install Netstat Without Internet?

Yes, if you have the net-tools package file (.deb, .rpm, etc.) on a local drive, you can install it offline using dpkg -i or rpm -ivh.

What Is The Difference Between Netstat And Ss?

ss is faster and more feature-rich, but netstat has a more familiar syntax. Both show network connections.

How Do I Install Netstat On A Docker Container?

Use the same package manager commands inside the container. For example, apt install net-tools in a Ubuntu container.

Does Netstat Work On All Linux Distributions?

Yes, net-tools is available for all major distributions, though the package name might vary slightly.

Conclusion

Installing netstat on Linux is a simple process that takes just a minute. Whether you’re on Ubuntu, CentOS, Arch, or any other distribution, the net-tools package gives you access to this classic utility. Remember to use sudo for installation and for commands that need elevated privileges.

Now that you know how to install netstat on linux, you can monitor network connections, troubleshoot issues, and manage ports with confidence. Keep this guide handy for future reference, and don’t hesitate to explore netstat’s many options.

If you encounter any problems, refer to the troubleshooting section above. Happy networking!