因为在 macOS 下实在仍受不了 VirtualBox 的各种 Bug 和低性能,转投熟悉的 VMware Fusion 后本来一直都挺稳定的,但在一次 Linked Clone 链接克隆中发现 NAT 网络下 VM 可以访问外网但宿主机和虚拟机之间的网络却无法 ping 通,查阅了非常多的资料仍然无解差点就要暴力选择添加一块新网卡做 host-only,最后发现重启下 VMware Fusion 网络就恢复了,这大概就是传说中的无脑重启解决一切问题。
2020 年 06 月 16 日 - 初稿
阅读原文 - https://wsgzao.github.io/post/vmware-fusion/
网上解决方案:
以上方法通通无效
# 重启 vmware network 服务解决问题
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start
VMware Fusion 安装完成后,会在 macOS 中新建两个网卡:vmnet1 以及 vmnet8 (在 /Library/Preferences/VMware Fusion
下可以看到)
这里仅对网卡 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
注意:只修改 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 的配置完毕。
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)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.