I use VirtualBox every day to test out new applications, new operating systems, how to configure, and even how to break things.
More how-tos
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.
Also: What are VirtualBox guest snapshots and how do you take them?
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
Requirements
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.
Also: How to create a Linux virtual machine with VirtualBox
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.
The first thing to do is open the VirtualBox application. If your guest OS is running, you’ll need to shut it down. You can either shut it down completely or save the current running state.
Select the guest operating system in the left sidebar and then click Settings in the top toolbar.
In the Attached to drop-down, select Bridged Adapter, which makes the guest operating system accessible from the LAN. Click OK and then start the guest. When the guest comes up this time, you should be able to now access it from the LAN.
You’ll need to locate the IP address for the virtual machine, which will vary depending on what operating system you’re using. For example, if the guest is Linux, you can view the IP address with the command ip a.
Also: How to change your IP address with a VPN (and why you should)
With that address in hand, you can access it because it now shares the same address scheme as the other machines on your LAN.
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.
Networking
Source: Networking - zdnet.com