Skip to content

Instantly share code, notes, and snippets.

@magnetikonline magnetikonline/README.md
Last active Jul 8, 2019

Embed
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 in 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 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 192.168.2.6 against a host-only interface of --ip 192.168.2.1 --netmask 255.255.255.0.

Ubuntu 18.04+

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

Ubuntu pre 18.04

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

Reference

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.