How to Install netstat Command in Linux

Introduction

Netstat is a command-line utility that can be used to monitor network connections and statistics. It is available on most Linux distributions and can be used to view active connections, routing tables, and a variety of other network-related information. In this guide, we will show you how to install and use the netstat command on Linux.

How to Install netstat Command in Linux

1. Check if netstat is installed:

The first step is to check if netstat is already installed on your Linux system. To do this, open a terminal window and type the following command:

which netstat

If the command returns a path, then netstat is already installed on your system.

2. Install netstat:

If netstat is not installed on your system, you can install it using the package manager of your Linux distribution.

For example, on Ubuntu and Debian systems, you can use the apt package manager to install netstat:

sudo apt update

sudo apt install net-tools

On CentOS and Fedora systems, you can use the yum package manager to install netstat:

sudo yum install net-tools

3. Verify the installation:

Once the installation is complete, you can verify that netstat is installed by running the which command again:

which netstat

If the command returns a path, then netstat is installed and ready to use.
[ad_1]

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.

[ad_2]

How to Install netstat Command in Linux

Netstat is a command-line tool that can be used to view network connections, routing tables, and interface statistics. It is available on most Linux distributions and can be used to troubleshoot network issues. In this tutorial, we will show you how to install and use the netstat command in Linux.

Prerequisites

  • A Linux system with root privileges
  • A terminal window/command line (Ctrl-Alt-T)

Installing netstat

The netstat command is available on most Linux distributions and can be installed using the package manager. For example, on Ubuntu and Debian, you can use the apt package manager to install netstat:

sudo apt update
sudo apt install net-tools

On CentOS and Fedora, you can use the yum package manager to install netstat:

sudo yum update
sudo yum install net-tools

Using netstat

Once the netstat command is installed, you can use it to view network connections, routing tables, and interface statistics. To view all active network connections, you can use the following command:

netstat -a

To view all listening ports, you can use the following command:

netstat -l

To view all established connections, you can use the following command:

netstat -e

To view the routing table, you can use the following command:

netstat -r

To view interface statistics, you can use the following command:

netstat -i

Conclusion

You have successfully installed and used the netstat command in Linux. You can now use it to view network connections, routing tables, and interface statistics. For more information about the netstat command, you can refer to the man page.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

GSTIN is 03EGRPS4248R1ZD.

Contact
Jassweb, Rai Chak, Punjab, India. 143518
Item added to cart.
0 items - 0.00