CentOS 7系统使用最小化安装后,在使用ifconfig命令时,会报错:

ifconfig :command not found

无法使用该命令的原因为:​最小化安装默认没有安装net-tools工具包导致

但是在使用命令安装时

yum install -y net-tools

会报错:

yum:command not found



解决办法:

1、​确认网络配置文件中,网络服务已经设置为开机自启:

在/etc/sysconfig/network-scripts/ifcfg-ens33 配置文件中​ONBOOT=yes

若为no,需改为yes后reboot重启验证ifconfig命令是否可用;



2、若使用方法1后仍报错,需安装net-tools工具包,使用命令

yum install -y net-tools

若yum命令不可用,需重新配置yum源,centOS7最小化安装后在/etc/yum.repos.d目录下有以下文件

CentOS-Base.repo  

CentOS-Debuginfo.repo

 CentOS-Media.repo  

CentOS-Vault.repo,有的还会有CentOS-CR.repo CentOS-fasttrack.repo CentOS-Vault.repo这三个,

目前生效的是网络yum源Base。


针对这种情况可使用本地磁盘挂载,也可以使用网络yum源,看个人需求:

1、本地磁盘挂载使用步骤:

      1)在/opt 目录中中新建文件夹cdrom


          #mkdir /opt/cdrom    挂载光盘


          #mount /dev/cdrom  /opt/cdrom

     2)把/etc/yum.repos.d中的网络yum源修改后缀名使其失效

           #cp CentOS-Media.repo CentOS-Media.repo.bk

     3)修改光盘yum源的配置CentOS-Media.repo 

[centOS 7]
 name=centOS 7
 baseurl=file:///opt/cdrom ---------->>这里修改为光盘的挂在地址
 #         file:///media/cdrom/
 #         file:///media/cdrecorder/
 gpgcheck=1
 enabled=1 ---------->>这里修改为1代表启用光盘yum源

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


          修改完成后保存退出

    4)现在再执行安装命令yum -y install net-tools,装完后在执行ifconfig既可出现网卡相关信息

2、配置网络yum源(以阿里云yum为例):

      #mv /etc/yum.repos.d/CentOS-Base.repo CentOS-Base.repo.bk

      #vi  /etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

执行安装命令yum -y install net-tools,装完后在执行ifconfig既可出现网卡相关信息