安装 centos 后,首先需要设置网络
我们先来 用 ifconfig 命令查看网络接口信息
[root@localhost ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.36.128 netmask 255.255.255.0 broadcast 192.168.36.255
inet6 fe80::952:59e1:f6c6:3932 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6b:b2:86 txqueuelen 1000 (Ethernet)
RX packets 3597 bytes 251976 (246.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 997 bytes 91049 (88.9 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 1000 (Local Loopback)
RX packets 76 bytes 6612 (6.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 76 bytes 6612 (6.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
这里因为我已经设置过网络,能够看到有 lo 和ens33 两个接口,其中lo是本地环回接口,另一个是我配置的真是网络接口。
如果没有配置,只会出现lo一个信息。我们可以如下命令添加网络:
[root@localhost ~]# ifconfig eth0 192.168.110.2
其中 eth0 是虚拟机当前linux系统第一个网卡,如果设置了多个网卡,可以用eth1、eth2...
192.168.110.2 是虚拟机的主机网络的同网段地址。
我们回车后再次运行ifconfig 就发现网络已经设置成功。
##如果我们输入ifconfig 时 提示 command not found
这时候说明没有安装网络相关工具,如下命令安装即可!
yum install upgrade
yum install net-tools