Skip to content

Instantly share code, notes, and snippets.

@magnetikonline magnetikonline/
Last active Oct 15, 2019

What would you like to do?
VirtualBox create host-only interface and attached to VM.

VirtualBox create host-only interface and attach

A host-only network interface is one created in software which appears on the host system.

This interface can then be attached to one or more VMs - allowing for connectivity between those VMs and free communication between the host system and connected VMs.

Create & attach interface

Create a new host-only interface:

$ vboxmanage hostonlyif create
# Interface 'vboxnetX' was successfully created

Note down created interface name (e.g. vboxnetX, referred to as IF_NAME for the following steps.

Set network range and disable DHCP for interface:

$ vboxmanage hostonlyif ipconfig IF_NAME --ip --netmask
$ vboxmanage dhcpserver modify --ifname IF_NAME --disable

List final host-only interface(s) configured:

$ vboxmanage list hostonlyifs

Attach network adapter to existing VM(s):

$ vboxmanage list vms
# "VM name" {VM_UUID}
# "VM name" {VM_UUID}
# "VM name" {VM_UUID}

$ vboxmanage modifyvm VM_UUID --nic2 hostonly --hostonlyadapter2 IF_NAME

At this point you will have a new host-only interface attached to one or more VMs.

Next step is to configure associated VM guest operating system(s) with the new attached interface.

Configure Ubuntu guests

In these examples configuring a VM guest with an ip address of against a host-only interface of --ip --netmask

Ubuntu 18.04+

$ cat /etc/netplan/interfaces.yaml
# network:
#     ethernets:
#         enp0s3:
#             addresses: []
#             dhcp4: true
#             optional: true
#         enp0s8:
#             addresses: []
#             dhcp4: false
#     version: 2

$ sudo netplan apply

Ubuntu pre 18.04

$ cat /etc/network/interfaces
# iface INTERFACE_ID inet static
# 	address
# 	netmask


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.