Home FAQ Linux Troubleshooting – netstat command not found in CentOS 7/8 And RHEL 7/8

Linux Troubleshooting – netstat command not found in CentOS 7/8 And RHEL 7/8

By sk
Published: Last Updated on 79.1K views

As you probably know, Netstat (network statistics) is a command line tool that can be used to check the network configuration and activity. The netcat command is not available in the minimal installation of RHEL 8, 7 and it's clones like CentOS 8 and 7. This brief tutorial describes how to get the netstat command working in CentOS 7, RHEL 7 systems.


An important note:

As one of our reader has pointed out in the comment section below, many of the old Linux networking commands have been deprecated in favor of their iproute2 counterparts. Netstat in particular has been replaced by the “ss” command which is available by default. If you still use netstat for any reason, this tip might help.


netstat command not found in CentOS 7/8 And RHEL 7/8

First we will see how to fix this error in CentOS 8 and RHEL 8 server editions.

Fix "netstat command not found" Error in CentOS 8 & RHEL 8

First, we need to find which package provides 'netstat' command using the following command:

# dnf provides */netstat

Or,

# dnf whatprovides */netstat

Sample output from my CentOS 8 server:

net-tools-2.0-0.51.20160912git.el8.x86_64 : Basic networking tools
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/netstat

find which package provides netstat command in centos 8 server

As you can see, the "net-tools" package provides "netstat" command.

So, let us install net-tools package as root user using the following command as root user:

# dnf install net-tools

Sample output:

CentOS-8 - AppStream                                                                                                                      1.5 kB/s | 4.3 kB     00:02    
CentOS-8 - Base                                                                                                                           4.5 kB/s | 3.8 kB     00:00    
CentOS-8 - Extras                                                                                                                         1.7 kB/s | 1.5 kB     00:00    
Dependencies resolved.
==========================================================================================================================================================================
 Package                               Architecture                       Version                                                Repository                          Size
==========================================================================================================================================================================
Installing:
 net-tools                             x86_64                             2.0-0.51.20160912git.el8                               BaseOS                             323 k

Transaction Summary
==========================================================================================================================================================================
Install  1 Package

Total download size: 323 k
Installed size: 1.0 M
Is this ok [y/N]: y
Downloading Packages:
net-tools-2.0-0.51.20160912git.el8.x86_64.rpm                                                                                             253 kB/s | 323 kB     00:01    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                     170 kB/s | 323 kB     00:01     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                  1/1 
  Installing       : net-tools-2.0-0.51.20160912git.el8.x86_64                                                                                                        1/1 
  Running scriptlet: net-tools-2.0-0.51.20160912git.el8.x86_64                                                                                                        1/1 
  Verifying        : net-tools-2.0-0.51.20160912git.el8.x86_64                                                                                                        1/1 

Installed:
  net-tools-2.0-0.51.20160912git.el8.x86_64                                                                                                                               

Complete!

Now you can use netstat command on your CentOS 8 system.

Fix "netstat command not found" Error in CentOS 7 & RHEL 7

First, we should find out which package provides 'netstat' command.

To find out that, run:

$ yum provides */netstat

Or,

$ yum whatprovides */netstat

Sample output:

yum provides */netstat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
net-tools-2.0-0.17.20131004git.el7.x86_64 : Basic networking tools
Repo : base
Matched from:
Filename : /bin/netstat

As you see in the above output, we need to install net-tools package in order to get netstat command.

So, let us install net-tools command using the following command from the Terminal:

$ sudo yum install net-tools

Sample output:

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.nbrc.ac.in
 * extras: mirror.nbrc.ac.in
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
--> Running transaction check
---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================================================================================================
 Package Arch Version Repository Size
========================================================================================================================================================================
Installing:
 net-tools x86_64 2.0-0.17.20131004git.el7 base 304 k

Transaction Summary
========================================================================================================================================================================
Install 1 Package

Total download size: 304 k
Installed size: 917 k
Is this ok [y/d/N]: y
Downloading packages:
net-tools-2.0-0.17.20131004git.el7.x86_64.rpm | 304 kB 00:00:05 
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1 
 Verifying : net-tools-2.0-0.17.20131004git.el7.x86_64 1/1

Installed:
 net-tools.x86_64 0:2.0-0.17.20131004git.el7

Complete!

That's it. Now you can use the 'netstat' command.

$ netstat

Sample output:

Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State 
tcp 0 0 server.ostechnix.com:ssh sk:54534 ESTABLISHED
Active UNIX domain sockets (w/o servers)
Proto RefCnt Flags Type State I-Node Path
unix 2 [ ] DGRAM 10304 /run/systemd/shutdownd
unix 2 [ ] DGRAM 10242 @/org/freedesktop/systemd1/notify
unix 5 [ ] DGRAM 6104 /run/systemd/journal/socket
unix 13 [ ] DGRAM 6106 /dev/log
unix 3 [ ] STREAM CONNECTED 14013 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 24798 
unix 3 [ ] STREAM CONNECTED 17856 
unix 3 [ ] STREAM CONNECTED 17874 
unix 3 [ ] STREAM CONNECTED 15064

[...]

unix 3 [ ] STREAM CONNECTED 17878 
unix 3 [ ] STREAM CONNECTED 17832 
unix 3 [ ] STREAM CONNECTED 17841 
unix 3 [ ] STREAM CONNECTED 14010 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 14710 /var/run/dbus/system_bus_socket
unix 2 [ ] DGRAM 11594 
unix 3 [ ] STREAM CONNECTED 16500 /run/systemd/journal/stdout
unix 3 [ ] STREAM CONNECTED 17809 
unix 3 [ ] STREAM CONNECTED 17836 
unix 2 [ ] DGRAM 13906 
unix 3 [ ] STREAM CONNECTED 17845

Hope this helps.


Suggested read:


Thanks for stopping by!

Help us to help you:

Have a Good day!!

You May Also Like

6 comments

Colinux September 25, 2018 - 5:17 pm

This is just another really stupid thing that RH have done (again).

WHY would they not include one of the most basic tools for setting up a system in the minimum install?

This is minimum install so I don’t expect much, but I can configure a nic to ping out and in, but don’t have one of the most basic tools available to check the default route, or listening ports.

It’s not like RH are concerned about disk space, so it must be that they are just a bunch of wankers!

Reply
Lyas Spiehler February 9, 2020 - 7:54 pm

Many of the old Linux networking commands have been deprecated in favor of their iproute2 counterparts. Netstat in particular has been replaced by the “ss” command which is available by default.

Reply
sk February 10, 2020 - 12:03 pm

Yeah, nestat is deprecated. I have added a note in the guide.

Reply
slavi February 9, 2020 - 10:17 pm

In my humble opinion this is a bad advice. On newer Linux (Redhat, Ubuntu,…) there is equivalent command “ss” with most of the switches are the same as “netstat”. Why is there no “netstat” anymore, because in rare cases it does not work correctly. But because some tools are expecting the “netstat” output new command “ss” was developed to work in all even rare conditions, but breaks backward compatibility with “netstat”. In my humble opinion “netstat” should only be installed for the users that have some old tool installed that is dependent on original “netstat” behaviour. This is almost non of the users.

Reply
sk February 10, 2020 - 12:02 pm

Yes, you’re right. Some people still use netstat.

Reply
Barry February 10, 2021 - 4:28 pm

My daily work I work on enterprise AIX systems, HPUX and Solaris. They ALL run netstat. Then I come over to CentOS 7 and no netstat which is a PITA. I also support a CentOS 4 system which is running a medium sized business. Is a pleasure to work with, has all the standard UNIX tool sets, including netstat, and does not have all the bloatware in current RHES versions. So yes, Some people still use netstat.

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More