Niklas' Blog

tech

For work I sometimes need to test or debug deployments on virtual machines. To do this I like to spin up a local vm in Virtualbox. Since I need to be able to ssh into it, it requires a host-only network adapter.

Whenever I provision a fresh machine of this kind, I have forgotten how to get the host-only adapter to work and it's hard to find the right instructions online since the process has changed so much during the various Ubuntu version.

So here it goes: How to set up a host-only adapter with Ubuntu 22.04 running in a Virtualbox:

  • Make sure the host-only adapter is connected to the machine. This is done in the settings of the VM in Virtualbox. Adapters can only be added or removed when the machine is down.

  • Logged into the VM run ip link show to list available network interfaces. Depending on what you configured there should be a number of devices listed. Most likely the loopback device, the NAT device and the host-only device, which should show as down. Now note the name of the host-only device

  • Open the netplan configuration at /etc/netplan/00-installer-config.yaml and add the host-only device like in the following example. In this case I'm assigning a static IP, but I think dhcp works too.

network:
  ethernets:
    enp0s3:
      dhcp4: true
    enp0s8: # This is the network device I identified earlier
      dhcp4: no
      addresses:
        - 192.168.56.104/24
  version: 2

  • Finally run netplan apply to apply the changes

  • Now you should see the interface as up when running ip a

#tech