Having only recently started using VirtualBox to build various VMs (Virtual Machines), it wasn’t immediately obvious to me how I could not only enable access to the outside world (Internet access, updates etc.), but also enable SSH to Linux boxes and such like via a private network within VirtualBox.
Eventually, I decided to configure each VM with two network adapters:
1) NAT (Network Address Translation)
This enables the VM to see access the Internet and outside world, but via a private IP address that cannot be seen from the host, or by the rest of your physical network outside VirtualBox.
2) Host-only
Once configured, this will allow you to access a private, virtual network consisting solely of your host and any guest machines. All of your VMs will be able to access each other, but nothing outside of this isolated Host-only network can get in.
The Host-only network needs to be configured within VirtualBox first as follows:
File > Preferences > Network > Add (host-only network)
VirtualBox will automatically assign an IP address for this new Host-only network, like below:
Ensure DHCP Server is disabled.
Once that’s been configured, you can assign this Host-only private network as a second adapter on your VM (the first being a NAT adapter).
When you come to configure the network adapters within the Operating System itself, your first adapter (NAT) should just be set to use DHCP.
For the second adapter you’ll need to assign it a fixed IP address and netmask based on the earlier Host-only configuration.
For example:
If you’re unsure about which of the network adapters within your VM’s Operating System relates to the NAT and Host-only adapters within VirtualBox, you can simply cross-check the MAC addresses for each device.
Your VMs can now access the outside world, communicate with each other, and for Linux/UNIX boxes, it means you can now connect from your local machine to your new VM using SSH and such like…happy days!