Networking – how to make 2 virtualbox vms able to see each other via internal network but also be able to access the internet

networkingvirtualbox

I have 2 VMs (A and B) running locally (on host H) with VirtualBox and I would like to be able to:

  1. ping A from B via an internal IP
  2. ping B from A via an internal IP
  3. ping 8.8.8.8 from A
  4. ping 8.8.8.8 from B
  5. access A:22 from H
  6. access B:22 from H

I'm currently using the NAT network setting on A and B, so I'm able to satisfy all requirements above apart 1 and 2.

I've tried changing this to internal network which satisfied only 1 and 2.

I've also used bridged networking which solved all those points but the problem is that A and B where now "exposed" in the local LAN by using 192.168.0.X type of addresses, which doesn't satisfy the "internal IP" requirement of 1 and 2.

What network configuration should I do on those 2 VMs to achieve this?

Best Answer

I solved it by adding 2 adapters on each VM. One for NAT and one for Host-only Adapter Network.

On the NAT I configured port forwards from 2201 to 22 etc. And when the VMs booted I had to configure their internal static IPs. They VMs are ubuntu so I had to edit /etc/network/interfaces and add:

auto eth1
iface eth1 inet static
address 10.0.0.101
netmask 255.255.255.0

and on the other VM:

auto eth1
iface eth1 inet static
address 10.0.0.102
netmask 255.255.255.0

After a shutdown -r now or a ifup eth1, the two VMs could ping each other via their internal IPs 10.0.0.101 and 10.0.0.102.

Related Question