How to connect to a VirtualBox virtual machine from your LAN


I use VirtualBox every day to test new apps, 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 a variety of purposes, and if I don’t configure them properly, those servers become inaccessible from my network. . When that happens, those servers are of no use to me.
To ensure that the virtual machine can be accessed from the Local Area Network (LAN), you must configure it properly.
I want to show you how to do it, so you can stop pulling your hair and wonder why it’s new WordPress deployment nowhere to be found.
Also: What are VirtualBox guest snapshots and how do you take them?
Thankfully, the configuration is actually pretty easy to take care of. Let me show you what you need to do.
How to connect a VirtualBox virtual machine from your LAN
Request
To make this work, you will need a running VirtualBox instance and a pre-existing guest virtual machine. It doesn’t matter which operating system you use as server or client, as the process is the same regardless.
That’s it. Let’s configure the network.
It’s all about the bridge
When you create (or configure) a virtual machine on VirtualBox, there is a Network section that includes tabs for each available network adapter. In most virtual machines, there will only be one adapter, called Adapter 1. In that tab, you’ll see a drop-down labeled Attached. 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 IP address by changing the header of an IP packet while it travels through the router. If you use NAT as the network adapter for the virtual machine, you will notice (when you start the virtual machine), the network on the client machine is different from the network on the host operating system. For example, your server has a network address of 192.168.1.62. If you leave your VM set to NAT, there’s a chance that the guest address will be something like 10.0.2.15.
Also: How to create a Linux virtual machine with VirtualBox
Theoretically, if set up properly, you should be able to access address 10.0.2.15 from 192.168.1.62, but usually that’s not the case and you won’t be able to access address 10.0.2.15 from 192.168.1.62 . However, you can access 192.168.1.62 from 10.0.2.15. That’s great if you just need to get out of the internet from guests. But if your guest is a server and you need to access it from LAN, you have to change NAT to Bridge. This is the way.
The first thing to do is open the VirtualBox application. If your guest OS is running, you need to turn it off. You can turn it off completely or save the current running state.
Select the guest operating system in the left sidebar and then click Settings in the top toolbar.
Go to the Settings window for the VirtualBox VM. Photo: Jack Wallen
In the Attachment drop-down list, select the Bridge Adapter, which makes the guest OS accessible from the LAN. Click OK and then start the guest. When the guest arrives this time, you will be able to access it from the LAN.
You will need to specify the IP address for the virtual machine, which will vary depending on the operating system you are using. For example, if the guest is Linux, you can see the IP address with the command ip a.
Also: How to Change Your IP Address Using a VPN (And Why You Should)
With that address in hand, you can access it because it now shares the same addressing scheme as the other machines on your LAN.
Change NAT to Bridged in the VirtualBox Settings window. Photo: Jack Wallen
And that’s all it takes to make sure your VirtualBox VMs are accessible from your LAN. Every time I set up a new virtual machine with VirtualBox, I make sure to change this setting so that my virtual machine is always ready for my network.