Netstat – derived from the phrases community and statistics – is a command-line utility utilized by system directors for analyzing community statistics.
It shows a complete method of statistics comparable to open ports and corresponding addresses on the host system, routing desk, and masquerade connections.
On this article, we are going to stroll you thru how one can set up the netstat command in totally different Linux distributions.
Tips on how to Set up netstat Command in Linux
The package deal that comprises netstat is named net-tools. On fashionable methods, the netstat utility comes pre-installed and there’s no want to put in it.
On older methods, nevertheless, you’re more likely to stumble upon an error once you run the netstat command.
bash: netstat: command not discovered
Due to this fact, to put in netstat on Linux distributions, run the command.
$ sudo apt set up net-tools [On Debian, Ubuntu and Mint] $ sudo yum set up 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 set up net-tools [On OpenSUSE]
As soon as put in, run the command beneath to verify the model of netstat put in.
# netstat -v
Tips on how to Use netstat Command in Linux
You’ll be able to invoke the netstat command on any of the Linux distributions to get totally different statistics in your community.
1. Viewing the Community Routing Desk
You utilize the -r
flag to point out the community routing desk to get one thing much like the output beneath.
# netstat -nr

The -n
possibility forces netstat to print addresses separated by dots as a substitute of utilizing symbolic community names. The choice is helpful for avoiding tackle lookups over a community.
2. Show Community Interface Statistics
Use the -i
flag to get an output of statistics of a community interface that’s configured. The -a
possibility prints all current interfaces within the kernel.
# netstat -ai

3. Present Community Connections
The netstat command utility helps choices that show lively or passive sockets utilizing the choices -t
, -n
, and -a
. The flags present RAW, UDP, TCP, or UNIX connection sockets. Including the -a
possibility, it’ll sow sockets prepared for connection.
# netstat -ant

4. Present Community Providers
To listing companies, their present state, and their corresponding ports, run the command.
# netstat -pnltu

On this article, we make clear how one can set up the netstat command and the way it’s used to verify a wide selection of community statistics.
It’s additionally necessary to level out that netstat has been deprecated and as a substitute, ss utility has taken its place in displaying extra refined community statistics.