centos7中没有安装ifconfig命令

centos7中没有安装ifconfig命令

  初装centos 7时,运行config报 command not found 错误

  ifconfig命令是设置或显示网络接口的程序,可以显示出我们机器的网卡信息,可是有些时候最小化安装CentOS等Linux发行版的时候会默认不安装ifconfig等命令,这时候你进入终端,运行ifconfig命令就会出错

[root@localhost yum.repos.d]# ifconfig
-bash: ifconfig: command not found

  这是我们首先会想到是不是环境变量里没有ifconfig命令的路径,因为ifconfig是在/sbin路径下的,以root用户登录才可以运行,可是我们上边是以root用户登录的啊,不急,我们来看看root用户的环境变量

[root@localhost yum.repos.d]# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

  看到没,我们的环境变量里有/sbin这个路径,也就是说说如果ifconfig命令存在并且就是位于/sbin目录下的话我们肯定就是可以运行的,那么我们就看看/sbin目录下有没有ifconfig命令吧

[root@localhost yum.repos.d]# ls /sbin|grep ifconfig

  结果表明我们的/sbin目录下并没有ifconfig命令,所以我们的结论是:我们的CentOS里边是没有安装ifconf

[root@localhost yum.repos.d]# yum search ifconfig
================================================= Matched: ifconfig ==================================================
net-tools.x86_64 : Basic networking tools

  看到了吗,bash也是有分割线的,当然这不是在重点,重点是通过yum search 这个命令我们发现ifconfig这个命令是在net-tools.x86_64这个包里,接下来我们安装这个包就行了

[root@localhost yum.repos.d]# yum install net-tools.x86_64

  这是我们已经安装好ifconfig这个命令了,我们试一下

[root@localhost yum.repos.d]# ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet xxx.xxx.xxx.xxx  netmask 255.255.255.0  broadcast xxx.xxx.xxx.xxx
        inet6 fe80::20c:29ff:fe2a:d794  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:2a:d7:94  txqueuelen 1000  (Ethernet)
        RX packets 29021  bytes 36547442 (34.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6659  bytes 563305 (550.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 8  bytes 632 (632.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8  bytes 632 (632.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

  windows里的ipconfig命令到了linux为什么有事还不是必须安装的,ifconfig命令来源于net-tools,这个包里有ifconfig,netstat,whois等命令,所以之前这些命令你都是运行不了的

原文地址:https://www.cnblogs.com/Lance-WJ/p/14007369.html