Windows版本:Windows 8.1;

VMware版本:15;

Linux版本:rhel-server-7.4;

 

VMnet1,仅主机模式,Linux仅可以和Windows连接,Linux不能上网;

VMnet8,NAT模式,Linux可以和Windows连接,Linux能上网。

 

Windows配置VMnet1和VMnet8

通过VMware在Windows上安装好Linux虚拟机后,在Windows上可以看到VMnet1和VMnet8适配器,如图:

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Windows

在对应的适配器上右键,点击属性可以配置各自IP地址,如图:

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_VMnet8_02

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Windows_03

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_VMnet1_04

 

VMware配置网络

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_VMnet8_05

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Windows_06

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Windows_07

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Linux_08

 

Linux配置VMnet1和VMnet8

vi /etc/sysconfig/network-scripts/ifcfg-ens33
内容如下:

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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=2d854660-81fb-4211-9283-f7f699cd2738
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.128.111
GATEWAY=192.168.128.2
NETMASK=255.255.255.0
DNS1=8.8.8.8

PREFIX=24
IPV6_PRIVACY=no

 

注:IPADDR需要与VMnet1或VMnet8在同一网段,且在DHCP设置起始地址范围之内。

最后执行service network restart命令,

可以执行ping www.baidu.com,看看是否可以上网,如果成功的话,如图:

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_VMnet8_09

否则需要检查虚拟机右下角网络适配器,如图: 

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Windows_10

如果不是NAT模式,将其修改为NAT模式

如果出现如下错误:

Restarting network (via systemctl):  Job for network.service failed because the control process exited with error code. See "systemctl status network.service" and "journalctl -xe" for details.
                                                           [FAILED]
 

按照提示执行命令:

systemctl status network.service

错误信息如下:

● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: failed (Result: exit-code) since Tue 2019-01-22 06:02:19 CST; 1min 27s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 5861 ExecStart=/etc/rc.d/init.d/network start (code=exited, status=1/FAILURE)

Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 network[5861]: RTNETLINK answers: File exists
Jan 22 06:02:19 bigdata111 systemd[1]: network.service: control process exi...=1
Jan 22 06:02:19 bigdata111 systemd[1]: Failed to start LSB: Bring up/down n...g.
Jan 22 06:02:19 bigdata111 systemd[1]: Unit network.service entered failed ...e.
Jan 22 06:02:19 bigdata111 systemd[1]: network.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

 

解决办法:

(1)停止并禁用虚拟机 NetworkManager 服务

systemctl stop NetworkManager

systemctl disable NetworkManager

NetworkManager区分大小写

(2)关闭虚拟机重新生成网卡 MAC 地址(这一步不一定需要)

Windows上Linux虚拟机网络配置(VMnet1和VMnet8)_Linux_11

 

(3)重启虚拟机网络服务

systemctl restart network