1

I have a network of test VMs whose traffic I need to go through another VM (in VMware). I figured the best solution would be to set the 'router' VM to have both a NAT and a host-only adapter and put the test VMs on a host-only network.

I changed /etc/network/interfaces on router VM:

...
auto vmnet8
iface vmnet8 inet static
  address 10.10.10.15
  gateway 10.10.10.2
  broadcast 10.10.10.255
  netmask 255.255.255.0

auto vmnet9
iface vmnet9 inet static
  address 10.10.11.1
  broadcast 10.10.11.255
  netmask 255.255.255.0

And an example VM on the host-only network:

...
auto vmnet9
iface vmnet9 inet static 
  address 10.10.11.12
  broadcast 10.10.11.255
  netmask 255.255.255.0
  gateway 10.10.11.1

I've also set /proc/sys/net/ipv4/ip_forward to 1 on the router VM

As of right now, the router VM has internet access and can talk to the other VMs but is not forwarding the traffic from the host-only network to the NAT connection.

1

You need iptables rules to forward input on one ethernet dev to output to the other device, and vicey-versa so traffic can flow both ways. Then you'll need to set appropriate routes on whatever devices you want to connect to your virtual subnet

I use (do the same in virtualbox, one nic on bridged to my LAN, other on "internal only"). I set this as a script to run on boot via rc.local on the "router" VM...

#!/bin/bash
/sbin/iptables -F
/sbin/iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
/sbin/iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
  • Thanks! Now my host-only VMs are successfully able to reach the internet but virtualbox is dropping any response packets. I started wireshark on the host and the router VM and pinged 8.8.8.8 from one of the host-only VMs. The host and router sees the ICMP request but only the host sees the response (it's not being forwarded by virtualbox). Have you run into this problem? – Ryan Lehmkuhl Jun 17 '17 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.