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

2

2

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?

cherouvim

Posted 2016-02-13T17:00:42.447

Reputation: 819

What are the ip adresses of VM a, and b? – Smeerpijp – 2016-02-13T17:25:43.483

Answers

3

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.

cherouvim

Posted 2016-02-13T17:00:42.447

Reputation: 819

0

Change the network adapters to NAT (one network card per VM is enough). So they will be exposed only to the host and not the network the host is running on and you will be able to add a check mark to all 6 points you mentioned.

If some point later you will have to give access to those VMs from the network your host is attached to, you will be able to do so with forwarding rules.

Zina

Posted 2016-02-13T17:00:42.447

Reputation: 1 855

By using NAT I can't satisfy #1 and #2, because both machines use 10.0.2.15 for themselves and 10.0.2.2 for the host. I don't know how A and B see each other that way. – cherouvim – 2016-02-13T20:38:16.800

Check your NAT settings, as both VMs should have different IPs. Check the MAC addresses of the VMs. They should be different. Have you setup the IPs as static or did you get it from the NAT DHCP? – Zina – 2016-02-13T20:41:30.833

I'm using VirtualBox and by using NAT in the VM's Settings > Network, the VM gets 10.0.2.15 and I don't know if this can be changed. – cherouvim – 2016-02-13T20:44:17.437

Per VirtualBox Networking manual every VM should get a different IP. Check also here Fine Tuning NAT

– Zina – 2016-02-13T20:48:40.397

This answer is not correct. With NAT every VM gets the exact same IP address and cannot see each other, just the host. I think the confusion comes from the (very different, but confusingly named) "NAT Network" mode, in which a NATted virtual network is created and all VMs join in. – MarioVilas – 2018-04-19T14:28:17.903