How to do networking between virtual machines in VirtualBox?

93

42

I have two virtual machines in VirtualBox. I would like to do networking between them. For the moment I have the default configuration on both, but they seem to have the same IP-address 10.0.2.15. I would also like to be able to use Internet with both, and that is Possible now.

By default the network-setting is NAT, but it seems like they cannot network internally since they have the same IP. But If I change to internal networking I guess that I cannot access Internet with the virtual machines.

How can I set up networking between virtual guest AND have access to Internet on them?

Jonas

Posted 2010-03-14T09:48:36.853

Reputation: 21 007

Answers

57

Have you tried this Virtual Networking Guide ?

The virtual machine receives its network address and configuration on the private network from a DHCP server integrated into VirtualBox. The IP address thus assigned to the virtual machine is usually on a completely different network than the host. As more than one card of a virtual machine can be set up to use NAT, the first card is connected to the private network 10.0.2.0, the second card to the network 10.0.3.0 and so on.

I think what you're looking for is "Internal Networking" , connecting internal VMs each other.

You can use a VM's "Settings" dialog in the VirtualBox graphical user interface. In the "Networking" category of the settings dialog, select "Internal Networking" from the drop-down list of networking modes. Now select the name of an existing internal network from the drop-down below or enter a new name into the entry field.

Ye Lin Aung

Posted 2010-03-14T09:48:36.853

Reputation: 5 444

1

The link in the previous comment didn't work for me, this appears to be the correct one: http://blog.techprognosis.com/how-to-enable-dhcp-in-virtualbox-4/

– Nicola Musatti – 2015-04-21T23:17:01.973

1Thanks, that's right. Internal Networking is working but doesn't come with DHCP so I tried the Bridged solution and that works fine. Thanks. – Jonas – 2010-03-14T11:01:01.670

This didn't work for me until I set it a static IP. – VaTo – 2016-02-24T00:43:05.937

internal networking works, but both machines lose connectivity to internet. – pwned – 2017-03-23T11:18:37.277

2http://www.virtualbox.org/manual/ch08.html#vboxmanage-dhcpserver – Joe Internet – 2011-08-31T21:30:12.880

3

@Joe Internet your link is OK, but I only understood it after reading http://blog.techprognosis.com/2011/02/28/how-to-enable-dhcp-in-virtualbox-4.html. That said, I got the internal network running. I was not able to select host-only or bridged mode because suitable adapters are missing.

– bernd_k – 2011-09-24T17:19:34.607

31

I found the following solution for my environment:

  • first adapter with internal network to access the other VM-
  • second adapter with NAT to access the internet.

Those settings can be done by the GUI Oracle VM VirtualBox Manager. Initially I had the same problem as Jonas, I missed DHCP. Finally I found this article (archived copy, original link is dead) and I used:

VBoxManage dhcpserver add --netname intnet --ip 10.13.13.100 --netmask 255.255.255.0 --lowerip 10.13.13.101 --upperip 10.13.13.254 --enable

from the command line. Afterwards it worked fine.

I dare say that the manual is a poor resource, as most of the configuration of VirtualBox on a Windows host can be done by the GUI and it is a severe inconvenience that one can't configure DHCP with the GUI.

My environment: I'm running portable VirtualBox 4.1.2r73507 on Windows 7 64 bit. Currently host-only and bridged mode not working, because host-only adapter is missing. I have a problem similar to that described in a german question on Virtual Box forum, I have no host only adapter.

bernd_k

Posted 2010-03-14T09:48:36.853

Reputation: 1 181

I already have an intnet dhcpserver that somehow came by default when I installed virtualbox 4.3.x, but it doesn't connect to internet when I use nat with that. – pwned – 2017-03-23T11:17:58.427

12

This is how I connect vbox guests in NAT mode only (tested on VirtualBox 4.2.4).

Just use the gateway IP to go from one guest to the host. Then use port forwarding to "proxy" the host traffic into the other guest.

For instance if guest A wants to reach a guest B service that listen on port 1000, A has to use the gateway IP (for the first NAT interface it is 10.0.2.2). Then you need to configure port forwarding on guest B so that all traffic received by the host on port 1000 go to guest B on port 1000.

This might not work for every service but it seems to work just fine for ssh, salt, ...

In conclusion, you don't necessary need host-only mode to connect multiple guests but I don't mean to say that host-only mode is not the best option for your use case.

user173653

Posted 2010-03-14T09:48:36.853

Reputation: 121

+1 for simplicity and being very straightforward! – Emre Sevinç – 2015-07-14T14:35:20.327

1This worked flawlessly for my use case (testing ie8 on an xp guest connecting to a server in a linux guest). – Ted – 2014-03-07T16:01:19.723

9

You need the host-connection LAN type (something like that in english version) on guest machines and bridge-connection on your host-machine.

stim

Posted 2010-03-14T09:48:36.853

Reputation: 1 294

3

(answer to question by bernd_k)

For sharing files between the host and guests, one actually shares directories rather than files.

If the network mode is bridged or NAT, then the host and guests are each equal network partners. Although the whole setup is contained in the one host, network-wise they are all equal on the network, as if they were physical machines. (NAT is sometimes more problematic to use than bridged.)

This way, any shared folder in any computer, virtual or physical, is available to all. Because not all virtual machines may be turned on all the time, it makes sense to setup one folder of the host as the shared folder. The host then shares the folder, and the virtual machines use it as-is or as a mapped drive.

The following article explains with great detail how to share folders in Windows :
How do I share folders in Windows 7 with the Shared Folder Wizard?

harrymc

Posted 2010-03-14T09:48:36.853

Reputation: 306 093

2Your hints are valuable at a later stage, but before sharing files or folders you must be able to ping the other machine. – bernd_k – 2011-09-25T16:01:51.870

2

I have two network cards on my Oracle VM XP PC

1st Bridged with a fast IP address as im using this as a client with a server network configuration. Changed the default gateway to the same as network card two (Nat 2nd)

2nd Nat With obtain IP address from Oracle VM

works fine!

Malcolm

Posted 2010-03-14T09:48:36.853

Reputation: 21

2

I did the following steps and it worked fine with me finally (on CentOS VB):

  • Use the NAT for the Primary Network adapter (Settings -> Network -> Adapter1 "attached to NAT").
  • Add another adapter (Settings -> Network -> enable Adapter2 "attached to Host-only Adapter") -> set "Promiscuous Mode" to "Allow All".
  • Start the VB.
  • Add another network interface (cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth1).
  • Change the MAC address for eth1 according to the one which appears in the Adapter2 ((Settings -> Network ->).
  • Restart the network "service network restart"

Then this VB should access the Internet and could be accessible from the others (VBs and local machine).

Note:

The NAT adapter will be used to access the Internet while the Host-Only adapter will be used for networking access between any other VBs and the local machine as well.

Moll

Posted 2010-03-14T09:48:36.853

Reputation: 21

0

I don't know if it will work, but my idea is:

  1. Change IP to diff number in only one virtual machine (in NAT mode).

  2. Change other virtual machine to Bridged.

  3. Set settings on both systems to machines find each other. Restart everything.

If 1+3 or 1+2+3 don't work, try this: Make a Shared Folder on host machine and share the folder to the 2 virtualbox machines on virtualbox settings. Restart and voilá?

I know the second option is a workaround.

H_7

Posted 2010-03-14T09:48:36.853

Reputation: 109

0

Change the network attached to Bridged Adapter in the Network under Setting.

That's it; It can connect two virtual PCs.

ami

Posted 2010-03-14T09:48:36.853

Reputation: 11