I need to give Internet access to a VM under Vmware fusion 7 in Host-Only mode. I know how to do it in Linux, with the following IPtables rules:
sysctl -w net.ipv4.ip_forward=1
iptables -A FORWARD -o eth0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
But I can not find out how to do it in MacOS Sierra. Any help?
Thanks in advance!
Best Answer
To enable NAT for a host-only network in VMware Fusion do the following:
Enable forwarding by adding a file /etc/sysctl.conf with the content:
and reboot
Connect the Mac to the host-only network and make a note of the network/netmask of the host.only network:
Enter
ifconfig
to get the vmnet IP of the MacIn the IP setting of the guest VM enter an IP/netmask according to the host-only network settings (with the example above that's in the range 192.168.9.2-254/255.255.255.0), a gateway (the vmnet3 IP of the hosting Mac from step 3 - here: 192.168.9.1) and a DNS server.
Open the pf.conf file with:
and add the lines:
after the line
rdr-anchor "com.apple/*"
.Depending on your Mac and your network configuration only one interface is sufficient (either en0 or en1). Also use the proper network/netmask (your vmnet config instead of 192.168.9.0/24)!.
Save the file and exit nano.
Check your pf.conf with:
If no error occurs enable pf with:
After a reboot you have to relaunch pf because it's not started automatically while booting. To launch pf while booting check step 4 in this answer: What is the modern way to do port-forwarding on El Capitan? (forward port 80 to 8080)