I use VirtualBox every day to test out new applications, new operating systems, how to configure, and even how to break things.
I also use virtual machine technology to deploy servers that I use for various things, and if I don’t configure them correctly, those servers won’t be reachable from my network. When that happens, those servers are of zero use to me.
To ensure that a virtual machine is reachable from your Local Area Network (LAN), you must configure it properly.
I want to show you how to do just that, so you can stop pulling out your hair and wondering why that new WordPress deployment is nowhere to be found.
Thankfully, the configuration is actually quite easy to take care of. Let me show you what you need to do.
How to connect a VirtualBox virtual machine from your LAN
To make this work, you’ll need a running instance of VirtualBox and an available guest virtual machine. It doesn’t matter what operating system you use as either the host or the guest, as the process is the same regardless.
That’s it. Let’s configure networking.
It’s all about the bridge
When you create (or configure) a virtual machine on VirtualBox, there’s a Network section that includes tabs for each available network adapter. In most virtual machines, there’ll only be one adapter, called Adapter 1. In that tab, you’ll see a drop-down labeled Attached to. By default, that drop-down is set to NAT.
NAT stands for Network Address Translation and is the process of mapping an IP address to another by changing the header of IP packets while in transit via a router. If you use NAT as your network adapter for the virtual machine, you’ll notice (when you boot the virtual machine) that the network on the guest is different than that of the host OS. For example, say your host machine has a network address of 192.168.1.62. If you leave your virtual machine set to NAT, it’s likely the address for the guest will be something like 10.0.2.15.
Theoretically speaking, if set up properly, you could reach 10.0.2.15 from 192.168.1.62, but most often, that is not the case, and you won’t be able to reach the 10.0.2.15 address from 192.168.1.62. However, you can reach 192.168.1.62 from 10.0.2.15. That’s great if you only need to get out to the internet from the guest. But if your guest is a server and you need to be able to reach it from the LAN, you must change NAT to Bridge. Here’s how.
And that’s all there is to ensuring that your VirtualBox virtual machines are accessible from your LAN. Every time I set up a new virtual machine with VirtualBox, I make sure to change this setting so my VMs are always available to my network.