前言
因为在macOS下实在仍受不了VirtualBox的各种Bug和低性能,转投熟悉的VMware Fusion后本来一直都挺稳定的,但在一次Linked Clone链接克隆中发现NAT网络下VM可以访问外网但宿主机和虚拟机之间的网络却无法ping通,查阅了非常多的资料仍然无解差点就要暴力选择添加一块新网卡做host-only,最后发现重启下VMware Fusion网络就恢复了,这大概就是传说中的无脑重启解决一切问题。
更新历史
2020年06月16日 - 初稿
阅读原文 - https://wsgzao.github.io/post/vmware-fusion/
问题描述
- 创建1台NAT网络类型的CentOS虚拟机,IP为默认DHCP段的192.168.184.128,宿主机和虚拟机网络互通,虚拟机可以正常访问外网
- 创建1台Linked Clone链接克隆CentOS虚拟机,IP为192.168.184.129,宿主机和虚拟机网络无法互通,虚拟机可以正常访问外网
解决方案
网上解决方案:
- 检查macOS是否联网
- 检查macOS是否给予VMware权限
- 重启虚拟机
- 重启VMware
- 重启macOS
以上方法通通无效
# 重启vmware network服务解决问题
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start
修改 VMware Fusion networking
配置 VMware Fusion 虚拟网络配置
VMware Fusion 安装完成后,会在macOS中新建两个网卡:vmnet1以及vmnet8(在 /Library/Preferences/VMware Fusion
下可以看到)
- vmnet1 是 Host-only 模式
- vmnet8 是 NAT 模式
这里仅对网卡vmnet8 进行修改(修改过程中需关闭VMWare Fusion)
sudo vi /Library/Preferences/VMware\ Fusion/networking
VERSION=1,0
answer VNET_1_DHCP yes
answer VNET_1_DHCP_CFG_HASH E805FD2F642680617F0D09147C8D5C5ED962ED29
answer VNET_1_HOSTONLY_NETMASK 255.255.255.0
answer VNET_1_HOSTONLY_SUBNET 172.16.131.0
answer VNET_1_VIRTUAL_ADAPTER yes
answer VNET_8_DHCP yes
answer VNET_8_DHCP_CFG_HASH ABBB4D6B9DEC5639F2756A1991B197986AB5597E
answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
answer VNET_8_HOSTONLY_SUBNET 192.168.184.0
answer VNET_8_NAT yes
answer VNET_8_VIRTUAL_ADAPTER yes
add_bridge_mapping en0 2
- 将 DHCP 设置为 no, 即使用静态IP。 将 SUBNET 修改为自己想用的网段,比如自定义192.168.111.0网段
- 保存退出
注意:只修改 vmnet8 的配置, 不要修改vmnet1的配置。
sudo vi /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
# VMware NAT configuration file
# Manual editing of this file is not recommended. Using UI is preferred.
[host]
# NAT gateway address
ip = 192.168.184.2
netmask = 255.255.255.0
# VMnet device if not specified on command line
device = vmnet8
# Allow PORT/EPRT FTP commands (they need incoming TCP stream ...)
activeFTP = 1
# Allows the source to have any OUI. Turn this on if you change the OUI
# in the MAC address of your virtual machines.
allowAnyOUI = 1
# Controls if (TCP) connections should be reset when the adapter they are
# bound to goes down
resetConnectionOnLinkDown = 1
# Controls if (TCP) connection should be reset when guest packet's destination
# is NAT's IP address
resetConnectionOnDestLocalHost = 1
# Controls if enable nat ipv6
natIp6Enable = 0
# Controls if enable nat ipv6
natIp6Prefix = fd15:4ba5:5a2b:1008::/64
[tcp]
# Value of timeout in TCP TIME_WAIT state, in seconds
timeWaitTimeout = 30
[udp]
# Timeout in seconds. Dynamically-created UDP mappings will purged if
# idle for this duration of time 0 = no timeout, default = 60; real
# value might be up to 100% longer
timeout = 60
[netbios]
# Timeout for NBNS queries.
nbnsTimeout = 2
# Number of retries for each NBNS query.
nbnsRetries = 3
# Timeout for NBDS queries.
nbdsTimeout = 3
[incomingtcp]
# Use these with care - anyone can enter into your VM through these...
# The format and example are as follows:
#<external port number> = <VM's IP address>:<VM's port number>
#8080 = 172.16.3.128:80
[incomingudp]
# UDP port forwarding example
#6000 = 172.16.3.0:6001
设置网关为192.168.111.2,网关的IP要和上一步中的IP保持网关一致,至此VMware Fusion的配置完毕。
配置虚拟机
- 将虚拟机网络切换到NAT模式
- 打开虚拟机,配置虚拟机网络配置信息
vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.111.100 // 自定义的虚拟机IP, 需与VMware Fusion配置的IP在同一个网段上
GATEWAY=192.168.111.2 // 配置的网关地址
NETMASK=255.255.255.0 // 配置的掩码
DNS1=114.114.114.114 // macOS本机的DNS地址。 系统偏好设置-> 网络 -> 在左侧选择当前使用的网络,点击右下角的“高级”按钮 -> 切换Tab页,可找到DNS地址。
DNS2=8.8.8.8 // 同上
# 保存退出,重启网络服务
systemctl restart network
参考文章
Troubleshooting networking and internet connection issues in VMware Fusion (1016466)
网友评论