One of the best features of Virtual Box: Bridged Networking

One of my most used tools is Oracle’s Virtual Box. I’m a virtual machine addict. I use a dedicated virtual machine for every new client or project. It’s so nice to have a self contained environment that doesn’t interfere with other projects, software versions, or dependencies. It’s also easier to bring on another developer to the project. Give them a copy of the VM image, and they’re up and running.

In a typical web application development environment, the web server, application server, and database server are all running within the same VM. I develop and test locally, completely self contained. When I’m ready to show others ( another developer, QA, or the client ), I typically deploy the app to a publicly accessible demo or test environment.

This process works fine in most cases, but occasionally I find it useful to test, demo, or have another person use the application served directly off my virtual machine development environment. Maybe I have something that’s experimental that I don’t want to deploy yet. Or maybe I need to test with Internet Explorer which doesn’t run in my usual development environment (Ubuntu Linux).

In these cases, it’s really helpful to have the virtual machine be accessible by other machines on the network (either another VM, or another computer).

The default network setting for a virtual machine in Virtual Box is “NAT”. This essentially treats your host computer like a router, and the VM is “hidden” from the local network. (There are limited ways around this, but it involves port forwarding setups). Other computers on the network can’t directly access any servers or services running on the virtual machine.

Default Network Settings

Digging into the Virtual Box’s documentation (which is pretty good btw), I found a network setting that solves my problem. See the screenshot below:

Virtual Box Network Settings

If you change the network setting of the VM to “Bridged Adaptor”, the VM actually becomes just another computer on your local network. This means it will obtain an IP from your DHCP router just like all other devices, and its services (like a web server) are now accessible by all other machines on the local network. Awesome!

Bridged Network Settings

There are a couple limitations. Virtual Box accomplishes this trick by using “promiscuous” mode of your host computer’s network interface card. There are certain cases (involving WIFI) where this doesn’t work. See the documentation for details. In most cases though, you’re good to go.

To make this network setting change, the VM must be stopped. You can verify it worked by looking at the DHCP client list of your router. It will list your VM there with its own assigned IP address. Woohoo!

DHCPClientsUbuntu