A host-only network interface is created virtually in software which appears to the host system.
This interface can be attached to one or more VMs, allowing connectivity between those VMs and communication between the host system and VMs.
Note: VirtualBox 6.1.28
has made a change (restriction) to the default allowed network ranges. This behaviour can be overridden by creating a /etc/vbox/networks.conf
file on the host filesystem with the following contents to unlock all allowed ranges:
* 0.0.0.0/0 ::/0
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 192.168.2.1 --netmask 255.255.255.0
$ 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 network interface attached to one or more VMs.
Next, configure associated VM guest operating system(s) with the new attached interface.
In these examples configuring a VM guest with an ip address of 192.168.2.6
against a host-only interface of --ip 192.168.2.1 --netmask 255.255.255.0
(as shown in the example above).
$ ip link
$ cat /etc/netplan/interfaces.yaml
# network:
# ethernets:
# enp0s3:
# addresses: []
# dhcp4: true
# optional: true
# enp0s8:
# addresses: [192.168.2.6/24]
# dhcp4: false
# version: 2
$ sudo netplan apply
$ ip link
$ cat /etc/network/interfaces
# auto INTERFACE_ID
# iface INTERFACE_ID inet static
# address 192.168.2.6
# netmask 255.255.255.0