200

I've just installed CentOS7 as a virtual machine on my mac (osx10.9.3 + virtualbox) .Running ifconfig returns command not found. Also running sudo /sbin/ifconfig returns commmand not found. I am root. The output of echo $PATH is as below.

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/robbert/.local/bin:/home/robbert/bin

Is my path normal? If not, how can I change it?

Also, I don't have an internet connection on virtual machine yet, maybe that's a factor.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
RobSeg
  • 2,450
  • 14
    Try sudo /sbin/ifconfig. – Ramesh Jul 19 '14 at 11:34
  • Did you perhaps mean /sbin/ifconfig? Looking at my system, I can't find an /sbin/config either. BTW, what do you get from ls /sbin/ifconfig? – celtschk Jul 19 '14 at 11:35
  • Thank you, I tried, it returns command not found. I guess the net-tools package is absent. I'll try to fix my internet connection first to download net-tools. – RobSeg Jul 19 '14 at 11:36
  • Yes, I meant /sbin/ifconfig. ls /sbin/ifconfig doesn't exist so I'll have to install that. I guess that's it. I think it's very weird that it didn't install by default. – RobSeg Jul 19 '14 at 11:39
  • 7
    It isn't installed by default probably because it is regarded as obsolete: it is replaced by ip. – vinc17 Jul 19 '14 at 11:41
  • what locate ifconfig says – klerk Jul 19 '14 at 11:43
  • 13
    Try ip command. ifconfig is deprecated now – SHW Jul 19 '14 at 11:47
  • 3
    @Ramesh No need for sudo: /sbin/ifconfig is enough if you want to see settings. You only need sudo if you want to change settings (and then sudo ifconfig is enough). – Gilles 'SO- stop being evil' Jul 19 '14 at 12:01
  • 2
    @SHW Just because the author of the ip tool has decided that ifconfig was deprecated doesn't mean that the rest of the world has to stop using it. – Gilles 'SO- stop being evil' Jul 19 '14 at 12:02
  • 1
    I was under impression that Linux community had deprecated ifconfig. Anyway, thanks for enlightening :) – SHW Jul 21 '14 at 05:54

3 Answers3

328

TL/DR: ifconfig is now ip a. Try ip -s -c -h a.

Your path looks OK, but does not include /sbin, which may be intended.

You were probably looking for the command /sbin/ifconfig.

If this file does not exist (try ls /sbin/ifconfig), the command may just be not installed.

It is part of the package net-tools, which is not installed by default, because it's deprecated and superseded by the command ip from the package iproute2.

The function of ifconfig without options is replaced by ip specifying the object address.

ifconfig

is equivalent to

ip addr show

and, because the object argument can be abbreviated and command defaults to show, also to

ip a

The output format is somewhat different:

$ ifconfig
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:10553 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10553 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:9258474 (9.2 MB)  TX bytes:9258474 (9.2 MB)
[ ... ]

and

$ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
[ ... ]

Note the output is more terse: It does not show counts of packets handled in normal or other ways.

For that, add the option -s (-stats, -statistics):

$ ip -s addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast
    74423      703      0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    74423      703      0       0       0       0

But what you actually want to see may be this:

$ ip -stats -color -human addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast
    74.3k      700      0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    74.3k      700      0       0       0       0

It shows counts with suffixes like 26.1M or 79.3k and colors some relevant terms and addresses.

If you feel the command is too long, use the short options:
This is equivalent:

ip -s -c -h a
Volker Siegel
  • 17,283
  • 8
    +1 for ip. net-tools has been deprecated in favor of iproute2. – HalosGhost Jul 19 '14 at 18:44
  • @Kiwy Oh, I would'nt mind if you'd add some details of that debate (but leave out some body related details), I actually never used it myself. Somebody could even file a bug report on the problems you see, then? – Volker Siegel Jul 22 '14 at 19:41
  • 1
    As in this answer, the equivalent ifconfig command is ip addr. – a coder Dec 04 '15 at 19:13
  • @acoder Thanks for the useful hint, I expanded the answer accordingly. – Volker Siegel Dec 05 '15 at 06:53
  • is there a ip xxx command for receiving the RX and TX packets like shown in ifconfig? – Stefan Krüger s-light Apr 26 '16 at 16:46
  • 1
    Yes - add the option -s (-stats, -statistics): ip -s addr – Volker Siegel Apr 26 '16 at 17:12
  • Those colors look terrible on a dark background. – Michael Hampton Sep 16 '16 at 21:08
  • 1
    Also may be helpful Deprecated Linux networking commands and their replacements: https://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ – Antônio Medeiros Jun 06 '17 at 17:05
  • 3
    Is deprecated because is ifconfig? They dont like the name? (yes i understand the point about functionality, but this is not a good reason to just remove the command) Why they dont just keep the command for compatibility with scripts in servers, for example creating a alias? Linux is starting to lost the point..., and more crap there are being done with linux, how systemd can be useful in a simple unix-like server? better migrate to freebsd before is too late? For example is practically impossible in a easy way to change the ip of some distros without restarting in text mode today! – Luciano Andress Martini Nov 28 '17 at 13:34
  • My case is that after doing yum update and yum upgrade, the net-tools is removed. I think it is because it's deprecated. Reinstall it solves the problem. – WesternGun Dec 13 '17 at 16:06
  • @MatejJ With "external" you mean "from the public internet" I asssume. This address is most probably managed by your router, by using NAT. That means the external address is the address of the router. The router forwards specific connections to your computer, which has a local address. So what seems to be the external address of your computer is actually not an address of your computer at all. Your computer does not even know that it has one. It could have multiple, too. – Volker Siegel Oct 24 '19 at 13:07
  • Sorry i meant ip address which is visible in lan network.. – Matej J Oct 24 '19 at 14:08
44

(verified) The default minimal install of CENTOS 7 does not install net-tools.

(verified) 'ifconfig' command will become available on installing package net-tools

-How to install net-tools through yum for the not so linux experts.

1) have a root privilege shell or be on the sudo list.

2a) At a root shell prompt (#)

yum install net-tools

2b) User account on the sudo list

sudo yum install net-tools

If the package is installed it will state so and exit yum. (Then it sounds like a path issue). If not installed yum will prompt the user to continue after a few local / network package checks. The install will (should) take but a moment.. presto ifconfig is now installed.

If you feel adventurous.. The equivalent of using ifconfig in displaying the interface / address information using ip

ip addr 
garethTheRed
  • 33,957
jsd
  • 441
3

Since everyone else has already provided the answer to finding ifconfig or available alternatives, I will provide some generic tips on how to get out of this situation because this is not the first or last time one would need to get hold of a command/package/utility on their system (basically I am teaching a person how to fish :). The instructions are for RHEL/CentOS.

Scenario 1: If that command already exists on another system:

  1. which ifconfig <- find the location of ifconfig. It might say /usr/sbin/ifconfig
  2. rpm -qf /usr/sbin/ifconfig <- This will give you the name of the rpm (like net-tools-2.0.0)
  3. sudo yum install net-tools <- Run this on your system to install the package.

Scenario 2: If you don't have another reference system, run the command yum whatprovides ifconfig. This will tell you the package name that contains the command and, if it already exists on your system, the path of the command. If the package doesn't exist, you just need to run sudo yum install to install it and you should be on your way.

These are generic instructions to find and install any package. I am not going into details about repos/other distros and other stuff here, so that you can get started.

HTH.