69

I'm using the following CentOS:

$ cat /etc/centos-release 
CentOS Linux release 7.0.1406 (Core) 

The commands nmap, netstat and lsof are not found on CentOS7. Why?

$ type -a nmap
bash: type: nmap: not found

$ type -a netstat
bash: type: netstat: not found

$ type -a lsof   
bash: type: lsof: not found

What should I do to make them work?

0

5 Answers 5

65

The package net-tools was deprecated in CentOS7 in favour of the iproute2 suite. You may either install it manually or check out this blogpost for replacement commands:

EDIT

Here is the URL to Red Hat's Bugzilla for RHEL7 that covers the deprecation of netstat in more detail: https://bugzilla.redhat.com/show_bug.cgi?id=1119297

Excerpt

As stated before, net-tools are deprecated thus shouldn't be used unless necessary. Behaviour in RHEL 7 is the same as in Fedora - net-tools is missing from minimal install, but is in @base (~= @standard in Fedora) which is installed in all non-minimal configurations.

There are also other tickets that deal with this such as IDs 682308 and 687920. Note that they are assigned to the Fedora project and are quite old.

3
  • 3
    lsof is not listed in your link of substitutions
    – mist
    Jan 4, 2015 at 0:01
  • It would be a lot more useful if you put the substitution of lsof directly in your answer
    – ericn
    Nov 16, 2015 at 2:50
  • 4
    I don't think that lsof was deprecated. It's just not installed by default. You can get it with yum install lsof.
    – Dan Keder
    Nov 18, 2015 at 16:01
35

just do:

yum install net-tools
1
  • 13
    It only took a few minutes for me to determine that netstat -plnt was replaced by ss -plnt using this link from @DanKeder's answer above. I think we should first try to make the distribution's recommended solutions work instead of reverting to deprecated approaches.
    – CodeMed
    May 16, 2017 at 19:43
12

Whenever you cannot find executables on a Red Hat based distro and you know their names, you should do 1 of the following 2 things.

Use repoquery

You can search the YUM repositories that are available to your system by using the command repoquery. If it isn't installed, then do a yum install yum-utils.

$ repoquery -qf */nmap
nmap-2:6.40-4.el7.x86_64

From here you can see which packages have an executable with those names. Here's all of them at once.

$ repoquery -qf */netstat */lsof */nmap
net-tools-0:2.0-0.17.20131004git.el7.x86_64
ctdb-tests-0:2.5.1-2.el7.x86_64
lsof-0:4.87-4.el7.x86_64
nmap-2:6.40-4.el7.x86_64
ctdb-tests-0:2.5.1-2.el7.x86_64

Now just do a sudo yum install lsof or sudo yum install nmap to install these missing packages.

Use yum search

You can also do a similar search using yum search <executable>.

$ yum search netstat     
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.advancedhosters.com
 * extras: mirror.cisp.com
 * updates: centos-mirror.jchost.net
================================================================== Matched: netstat ==================================================================
dstat.noarch : Versatile resource statistics tool
net-snmp.x86_64 : A collection of SNMP protocol tools and libraries
net-tools.x86_64 : Basic networking tools

With this approach you'll need to do a bit of digging to confirm that the resulting packages include the executable you're looking for. I typically look in there lit of files for what I want, but for that you'll have to use repoquery.

$ repoquery -ql net-tools.x86_64  | grep netstat
/bin/netstat
/usr/share/man/de/man8/netstat.8.gz
/usr/share/man/fr/man8/netstat.8.gz
/usr/share/man/man8/netstat.8.gz
/usr/share/man/pt/man8/netstat.8.gz

So using my first approach saves you the extra steps.

netstat's deprecation

Apparently in CentOS 7 netstat, which is part of the package net-tools has been officially deprecated, so you should be using ss (part of the package iproute2), going forward.

1
  • 1
    +1 for the repoquery and yum search commands.
    – fduff
    Apr 8, 2016 at 11:52
5

Upvoted slm's answer, just making it easier to find the info I used. I wanted to do:

netstat -nlp | grep httpd

Instead, on CentOS 7 I just did:

ss -nlp | grep httpd

Which works, didn't even have to install it on CentOS 7 minimal.

Do man ss for usage details.

2

It seems that you simply don't have these tools installed. On CentOS, you should be able to install them easily with yum. Try this:

$ yum install nmap netstat
4
  • 1
    Actually, this seems like a fairly valid answer. But, for the record, it does not take much time nor work to get 50 rep; if you really feel something should be posted as a comment, just wait until you can actually post it as one. (it won't take long)
    – HalosGhost
    Jul 23, 2014 at 19:17
  • 9
    Also note, netstat has been deprecated in favor of ss. Doubt it'll go away any time soon, but just fyi. I'd bet that ss is installed already.
    – phemmer
    Jul 23, 2014 at 19:52
  • @HalosGhost: It may take substantially longer than that, and you have to ask or answer some questions for it as well. Jul 23, 2014 at 21:14
  • 1
    OP specified CentOS 7. netstat is not a valid package in that distribution. Dec 9, 2014 at 16:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .