Centos7 不能联网且 ifconfig 出现 command not found

在虚拟机中以最小化方式安装 centos7 后无法上网,因为 centos7 默认网卡未激活,网络服务默认是关闭的状态。

而且在 sbin 目录中没有 ifconfig 文件,这是因为 centos7 已经不使用 ifconfig 命令了,已经用 ip 命令代替。

并且网卡名称也不是 eth0 了,而是改成 ifcfg-eth0 了。

解决ifconfig不可用:ip addr 即查看分配网卡情况。

激活网卡:在文件 /etc/sysconfig/network-scripts/ifcfg-eth0 中。

使用 vi 进入编辑模式,将 ONBOOT=no 改为 ONBOOT=yes 就 OK 了。

保存后重启网卡:service network restart

使用 ping 测试一下是否可以联网。

这样 yum,wget 等都可以用了。

Centos7 中安装 ifconfig 命令

不推荐再在 centOS7 中安装 ifconfig 命令,因为系统已默认使用 ip 命令替代 ifconfig 命令,不过仍然可以安装。

首先查找包括 ifconfig 的包

  1. yum search ifconfig

通过yum search 这个命令发现 ifconfig 这个命令是在 net-tools.x86_64 这个包里,运行

  1. yum install -y net-tools

同样地, netstat 命令也在 net-tools 包内。

参考资料