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.
VirtualBox
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.
![VirtualBox Network Adapter 1 image](http://ernieleseberg.com/system/wp-content/uploads/virtualbox-network1-1024x581.png)
Now go to Adapter 2, check Enable Network Adapter and choose Attached to ‘Host-only Adapter’.
![VirtualBox Network Adapter 2 image](http://ernieleseberg.com/system/wp-content/uploads/virtualbox-network2-1024x627.png)
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:
ip a
and you will get output like:
![Ubuntu 20.04 ip a before static IP](http://ernieleseberg.com/system/wp-content/uploads/ubuntu2004-ipa.png)
Netplan is the network management tool on Ubuntu these days, so forget the old /etc/network/interfaces
.
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.
![Netplan screenshot for static IP](http://ernieleseberg.com/system/wp-content/uploads/ubuntu2004-cfg1-1.png)
sudo netplan apply
ip a
![Ubuntu 20.04 ip a after static IP](http://ernieleseberg.com/system/wp-content/uploads/ubuntu2004-ipa2-1.png)
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.