Configuring Host-only Networks with VirtualBox
I wanted a clean Ubuntu Server so I spun up a VM using VirtualBox. I can start it in headless-mode with VBoxManager startvm 'Ubuntu Server' --type=headless
and have it run without a GUI.
To do anything useful then, I need to ssh into it. I could use port-forwarding but decided to read up a bit about networking. To give it a IP address, but not expose it to the LAN, one can add a host-only network device.
Once this is there, one needs to configure it in the guest OS. For Ubuntu, this means configuring the network adapter.
Running ls /sys/class/net
gives me a list of adapters. Adding
# Host only
auto enp0s8
iface enp0s8 inet dhcp
to /etc/network/interfaces
sets up the adapter to use DHCP to configure itself on boot.
After restarting the VM, I can now ssh into the machine. A possible improvement would be configuring it with a static IP and adding it to my hosts file.