1、在虚拟机中配置网络,改ONBOOT=yes后默认直接DHCP自动获取ip,但是这种方法会导致ip改变。这个时候,我们需要配置固定ip
2、进入/etc/sysconfig/network-scripts查看ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=fd6e53bc-3038-49eb-bdd7-46db0e45e1a6
DEVICE=ens33
ONBOOT=yes
3、我们需要修改部分参数,才可以固定ip,我们需要参考wm里面的网络配置
4、修改后的内容为如下,然后重启网络
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=fd6e53bc-3038-49eb-bdd7-46db0e45e1a6
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.42.139
DNS1=8.8.8.8
DNS2=114.114.114.114
GATEWAY=0.0.0.0
NETMASK=255.255.255.0
重启网络
service network restart
这样就成功
[root@node1 network-scripts]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@node1 network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.42.139 netmask 255.255.255.0 broadcast 192.168.42.255
inet6 fe80::5c0f:4b80:51f6:fac prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:dd:0b:2f txqueuelen 1000 (Ethernet)
RX packets 83287 bytes 8008347 (7.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 129807 bytes 24067155 (22.9 MiB)
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 8 bytes 672 (672.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 8 bytes 672 (672.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0