Access VirtualBox Guest Network From Outside

I have been looking for a way to enabling network inside virtualbox so that I can access it from anywhere thus being able to run various services inside virtual environment, trying out anything without any worries.

Here’s a simple how-to borrowed from archlinux wiki

Install bridge utils for creating bridge and uml_utilities for creating a tun device

pacman -S bridge-utils uml_utilities

Open the file /etc/udev/rules.d/60-vboxdrv.rules and add the following line to it

KERNEL==”tun”, OWNER=”root”, GROUP=”vboxusers”, MODE=”0660″

Then type the following command to load the tun module

modprobe tun

Now, let’s setup a bridge device to bridge network from your physical network interface to the virtual one

  • Create a bridge interface

brctl addbr br0

  • Set your interface in promiscous mode so it can accept packets from any interface

ifconfig <interface name> 0.0.0.0 promisc

  • Now, bridge the bridge interface with the real network interface

brctl addif br0 <interface name>

  • Now set the bridge interface to acquire IP address as your physical network interface would. eg if eth0 is your network interface and it acquires IP via DHCP then

dhclient br0

  • And finally add virtualbox host interface

VBoxAddIF vbox0 <VirtualBox user> br0

Now start VirtualBox and go to network settings. Select network interface as ‘host networking’ and interface device as ‘vbox0’.

Now you need to give an unused IP address in your IP range of the internet gateway. If you cannot provide that due to some reason then what you can do is create a virtual interface say eth0:0 then bind bridge network to that interface and setup NATing to pass packets between virtualbox and external network.

9 thoughts on “Access VirtualBox Guest Network From Outside

  1. Pingback: » Access VirtualBox Guest Network From Outside

  2. Mark

    Can you provide the link to the page you mentioned on the archlinux wiki? I would like to read that page also. Thank you.

    Also, the comment above mine (November 16, 2008 at 10:31 pm) links to a page with Trojan downloader malware on it. The site seems only to exist to spread this malware. Can you delete the comment to protect your other readers? Fortunately I use NoScript extension on Firefox and my Kaspersky antivirus program detected the malware.

    Thank you.

  3. mehul

    Hi keith,
    yes, the connection will go down when you bridge the interface because all the packets will pass from the physical interface to the bridge interface. What you need to do next is set the physical interface i.e. eth0, in your case to promiscous mode with the command
    ifconfig eth0 0.0.0.0 promisc
    After this step, set the IP address on br0 to the one which was given to eth0. You haven’t mentioned how you obrain your IP address so I cannot tell you how to set the IP address on br0. It will be the same way as you do for eth0. If you are not able to do this step, please tell me how you obtain your IP on eth0.
    Now, the internet connection should work fine.

  4. Craig

    HI,
    I am using Ubuntu 8.10.
    I am finding that the VM is unable to acquire an IP address from DHCP.

    I have read a number of posts on bridging and as far as I can gather it should be possible.

    Manual assignment of IP address works ok, just a bit of a pain.

    Any thoughts or suggestions?

    Another thought, have you tried to connect a virtual network to the bridge? would make it so much easier to deal with Multiple VMs.

  5. mehul

    hi Craig,
    Can you tell us how your network is setup and what are the stops you’ve followed, possibly then we can have a better idea about your problem.
    If you manually assign an IP, then are you able to ping that IP from outside the VM?

  6. Craig

    Hi Mehul,

    I am using a Dell laptop with Wireless connection as the connection and have followed the above directions.

    The LAN, it seems to have gone into promiscuous mode ok.

    The wireless adaptor is Broadcom BCM4312, I have not yet discovered whether it supports WDS or not.

    The IP assigned to br0 is from DHCP (BT Home hub).

    The Virtual machine using device vbox0, once manually assigned an IP can be reached by the host but not from the LAN, I can ping it from the host, I can ping the router from the host, but I cant ping the router from the VM, or the VM from any other machine on the LAN.

    I can ping between VM’s so it is looking likely that the adaptor in not supporting WDS.

    I have used VMware and that seems to work fine in Bridged mode, what are they doing that is so different?

Leave a Reply

Your email address will not be published. Required fields are marked *