Setup for the following technology:
- Windows 10 as host machine
- VirtualBox 6.0.18
- Guest OS is Ubuntu 20.04 (Focal Fossa) Server Beta [other versions since around 17.10 will work]
The aim is being able to access the guest on a static IP from the host to upload/download files and for the guest to be able to access the internet for API access to external services, apt update etc.
For this to happen the VM needs 2 network adapters:
- a host-only network adapter and configure the VM with a static IP address (for host to guest access)
- NAT network adapter (for access to the outside world)
To begin it is assumed you have downloaded the relevant Ubuntu iso file, created a new virtual machine through VirtualBox and gone through that install process. Do a
sudo apt update &
sudo apt upgrade to have the OS up to date and then
sudo shutdown now.
Back in VirtualBox. For this VM, choose settings and the Network.
Now go to Adapter 2, check Enable Network Adapter and choose Attached to ‘Host-only Adapter’.
OK to save the new setting and start the VM. You will now be back in the console window.
Ubuntu and Netplan
To see the network interfaces available type:
and you will get output like:
Netplan is the network management tool on Ubuntu these days, so forget the old
cd /etc/netplan ls -la
Depending on your Ubuntu version you will see a filename like 01-netcfg.yaml for my Ubuntu 20.04 server or 50-cloud-init.yaml for Ubuntu 18.04. Make a backup of that file in case something goes wrong and you need to roll back.
sudo cp 01-netcfg.yaml 01-netcfg.yaml.110420
Now edit the config file with your preferred text editor (vi, nano etc). In the image below I have added the other network interface as seen from ip a and have given it the static IP of 192.168.56.108.
sudo netplan apply
And that is it. I can now ssh / ftp into the guest server from the host on its static IP address and the guest can connect to the internet.