While I'm writing this post, VirtualBox 4.3.4 "NAT networks" (Network Address Translation Service) don't work properly (still experimental), so to have an internal network where VMs are accessible by Host but NOT from outside, and VMs are able to access networks outside host (as internet), I had to:
1) on Host VirtualBox Manager > file > preferences > network > host-only networks > add; on the (guest) VM settings > network > attached to > host-only adapter > set proper name
2) on Host, enable routing on the kernel:
$ sudo vi /etc/sysctl.conf
uncomment "net.ipv4.ip_forward=1"
3) on Host, enable NAT outside:
$ sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
$ sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
To make it persistent under a Debian/Linux Mint host, create a new ifup rule:
$ sudo vi /etc/network/if-up.d/iptables_NAT_vboxnet_out
#!/bin/sh
#
# Don't bother to do anything for lo or VBoxNets.
IFTYPE=$(echo "$IFACE" | cut -c1-2)
if [ "$IFTYPE" = lo -o "$IFTYPE" = vb ]; then
exit 0
fi
# Only run from ifup.
if [ "$MODE" != start ]; then
exit 0
else
iptables -t nat -A POSTROUTING -o "$IFACE" -j MASQUERADE
fi
$ sudo chmod ugo+x /etc/network/if-up.d/iptables_NAT_vboxnet_out
Reestart the Host to test.
No comments:
Post a Comment
deixe sua opinião