Configuring an host-only interface in Virtualbox

Lately I’ve been messing around with Linux in Virtualbox, both because dual-boot systems are a major pain in the backside and because I still can’t get Linux to recognize my graphics card properly. Since I’m experimenting with running a virtual server, I have no use for a graphical user interface and I could simply test if the web server is working correctly directly in the host operating system. I remembered I managed to get this to work in the past without having to configure anything inside the guest operating system in the past, but trying to get it to run now didn’t work out of the box, so I set forth to discover what was the problem.

Initial configuration

After I created my virtual machine, but before I started installing the operating system on it, I needed to tell Virtualbox that the machine was going to have two Ethernet interfaces instead of one. To do this, I had to right-click the virtual machine’s entry on the left pane and select Settings. Then, in the Settings dialog’s left pane, I had to select Network.

Virtualbox allows the user to configure up to 4 adapters per virtual machine, which are pretty much virtual network cards. By default, only Adapter 1 is enabled and attached to NAT. I selected Adapter 2, enabled it and chose Host-only adapter from the drop-down menu.

In theory, this should have been the only configuration required. I then proceeded onto installing a copy of Ubuntu Server and logged in for the first time.

How things went South

To check if things went according to plan, I booted the virtual machine and logged in as the user I had created during the installation process. I typed the command ifconfig to see if all the interfaces were active. I was expecting three to show up: one named lo, which is essentially a fake interface used by the machine to connect to itself, and other two whose names were to start with enp0s, which are supposed to be the “real” interfaces. However, only lo and enp0s3 (the NAT-attached adapter) were shown.

I asked Virtualbox where my host-only adapter was, but Virtualbox didn’t respond because… Well, it’s a piece of software and not a human being. I then needed to do a sanity check: is the second adapter actually recognized by the virtual machine? To do this, I used the command lspci | grep Ethernet and sure enough, there it was. The number 08 next to it tells me that its name is supposed to be enp0s8.

Let’s double-check with ip link show.

There it is! But apparently it’s currently down. Can I bring it up with ifup?


Configuring the missing interface

Then it struck me. Could it be that enp0s8 simply isn’t configured?

Let’s see if it is in our interface file with less /etc/network/interfaces.

For those unfamiliar with Linux, /etc/network/interfaces is a text file that contains the configuration options for all the network interfaces in our machine.

Okay, there we have our problem: /etc/network/interfaces isn’t telling our system that enp0s8 is available. Let’s fix this by editing the file, but first we’ll have to create a copy.

Pro-tipPro-tip: Whenever a tutorial on the Internet tells you to edit a configuration file in your Linux machine, it’s a good idea to create a backup copy of it. The easiest way is simply using the cp command with the following syntax:

cp filename filename.old

This way, in case something doesn’t work, you can simply revert to the default configuration by using the following command

cp filename.old filename

Let’s edit the interfaces file with sudo nano /etc/network/interfaces and append the following two lines to the interfaces file:

auto enp0s8
iface enp0s8 inet dhcp

Then we can press Ctrl + X followed by Y and Enter to save.

Let’s bring it up with ifup again.

Okay, that’s some progress! We should be able to connect to it using the IP address Let’s try

And yes, it survives reboots!

My reaction

About Andrea Luciano Damico 126 Articles
Andrea Luciano Damico is a freelance translator from Italy. Among his interests are linguistics, technology, video games, and generally being a chill guy. He runs Let's and