How to connect guest VM and host in Oracle VM Virtual Box

I work with the Oracle VM VirtualBox to switch quickly development projects. Most of them are e-commerce projects and run on a Linux OS. One time I got a ticket to fix an issue with the Internet Explorer. To reproduce the issue I need to connect guest VM with my Windows host. There are several ways to achieve it. I decided to add a second adapter.

First check if your VM is powered off. It’s necessary that the state of the machine is powered off and not saved. Otherwise, you can’t add any network adapter.

Open the VM setting and select the network tab.

Change the configuration as it is shown in the screenshot above. The network adapter checkbox should be already enabled. Set the Attached to field to NAT. Don’t select NAT-Network. Otherwise, you can use only one adapter per time.

Then add a second adapter by clicking the Adapter 2 tab. This time you need to enable the network adapter and select Attached to field to Host-only Adapter and select the Name field with the VirtualBox Host-Only Ethernet Adapter. If the name field is empty you need to create one in the settings of the VirtualBox under File | Host Network Manager.

Now you can start the virtual machine and open the terminal. Run the command ip add show. You will get the detailed information about your ip address.

You can find two networks in my setup. The one is the NAT network enp0s8 and the Host-only network enp0s17. The next step is to configure the IP address. On Debian/Ubuntu and Linux Mint OS open the file /etc/network/interfaces.

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

auto enp0s8
iface enp0s8 inet dhcp

auto enp0s17
iface enp0s17 inet static 

The loopback should be already defined. Add your network adapters definitions. Now you are able to connect to your guest VM. Try to connect via SSH as shown below:

You can also use only one adapter e.g. with the Host-only configuration, the Bridge Adapter or a Port Forwarding in the NAT configuration to achieve the same target. Let me know if use the same way or why you decided to take another way.


Leave a comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.