简体   繁体   中英

Connect to internet a VM on VMware throught another VM

I'm using VMware Workstation and I've two virtual machines (Ubuntu 64-bit). Both VMs are connected to the internet via Network Adapter NAT on the VMware settings.

My host machine is a classic Windows 10 with a VMware Network adapter ( VMnet8 ) used by both VMs (from what I've understood). I'm already able to ping both VMs from each other (they're on the same subnet)

I would like to use one of the two VMs as a "gate" to access the internet (which is provided by the host machine) on the other VM but, I can't understand how do I need to link the virtual network adapter to achieve my goal.

I would like to use a VM as a "gate" to the internet because I'm testing iptables and I would like to exercise to use it as a firewall, filtering traffic on the "gate" VM

First of all you have to make sure the IP forward is active. To do that you have to go to /etc/ and edit the file sysctl.conf using:

sudo nano /etc/sysctl.conf

Remove the commend (the #) from the line net.ipv4.ip_forward=1

About the iptables rules, you need a POSTROUTING rule

sudo iptables -t nat -A POSTROUTING -s your_ip/24 -o your_network_interface -j MASQERADE

where, in your case, the your_ip could be something like 192.168.125.0 (meaning all the traffic from the 125 subnet) and your_network_interface could be eth0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM