How to do networking between virtual machines in VirtualBox?

19
2014-04
  • Jonas

    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?

  • Answers
  • Ye Lin Aung

    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.

  • Eliseo Ocampos

    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 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.

  • stim

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

  • user173653

    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.

  • harrymc

    (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?

  • Malcolm

    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!

  • Dori

    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.

  • Moses

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

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


  • Related Question

    networking - Connecting to VirtualBox guest (ubuntu) from host (osx) via NAT?
  • EvanK

    I have a VirtualBox guest (running Ubuntu) configured with NAT through my host laptop (running OSX). It was my understanding that with NAT configured, I could access the guest from the host (w/o any port forwarding magic) but not from any outside machine...was I incorrect in thinking that?

    I would use bridged networking, but every time I switch networks (@ home, @ work, tethered to my phone), the guest's ip will change, right?


  • Related Answers
  • Jeff Knecht

    If you only need to access the guest from the host, then you want "Host only" networking. The IP address will appear if you hover over the network icon in the virtualbox window.

    If you need to get to the internet from your virtualbox guest, then you can use BOTH Host only and NAT (virtaulbox supports up to 4 different network adapters).

  • hbdgaf

    Generally from remote through nat is a pain. Depending on the virtualization technology, they each offer different methods to overcome this. Virtualbox has an option to forward port X to virtualized client if I remember properly...this would be required to do remote host access of client vm through nat.

  • Seasoned Advice (cooking)

    I'm not certain about a direct answer to your question, but I access my Ubuntu box (NAT) via OS X using the following, which does us port forwarding. Replace Ubuntu with the name of your guest.:

    VBoxManage setextradata Ubuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/HostPort" 2222
    VBoxManage setextradata Ubuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/GuestPort" 22
    VBoxManage setextradata Ubuntu "VBoxInternal/Devices/pcnet/0/LUN#0/Config/ssh/Protocol" TCP
    

    Then reboot (the guest), then from OS X: ssh -p 2222 localhost And you should be in the VM in the OS X Terminal