VirtualBox 7 | HOWTOs | User Manual

Install

@ Windows

chocolatey install virtualbox

Else use their installer

@ Ubuntu

sudo apt-get -y install virtualbox

@ @ RHEL/CentOS

# Download/Import its public key
sudo rpm --import https://www.virtualbox.org/download/oracle_vbox.asc
# Download/Install VirtualBox 5.5.20 (.rpm) 
sudo yum install -y \
    https://download.virtualbox.org/virtualbox/5.2.20/VirtualBox-5.2-5.2.20_125813_el7-1.x86_64.rpm  

Networking Modes

Manually set @ VirtualBox menu > Settings : NAT or Host-only Adapter

Network Mode : Host-only Adapter

Use for host-to-guest (WSL to VMs) and guest-to-guest (VM to VM) connectivity.

… VirtualBox creates a (virtual) loopback interface on the host … used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface.

# Get VM's IP CIDR per VirtualBox DHCP (File > Tools > Network Manager)
# Get VM IP of VM from VM : `ip -4 route` (src ...)
host='192.168.56.101'

ssh -i ~/.ssh/vm02 $user@$host

Network Mode : NAT

Use for standalone VMs requiring nothing more than web connectivity. Not as useful for inter-vm comms.

VirtualBox VMs are on separate network, but can use local-port forwarding through WWSL nameserver.

# @ VM Creation
user=x1 
# @ /etc/resolv.conf
wsl_nameserver='172.31.16.1'
host_port=2222

ssh -p $host_port ${user}@$wsl_nameserver

PKI Setup

keyname=vm02

ssh-keygen -f ~/.ssh/$keyname
ssh-copy-id -i ~/.ssh/$keyname $user@$host

# Session:
ssh -i ~/.ssh/vm02 $user@$host

@ ~/.ssh/config

Host vm02
    HostName 192.168.56.101
    User x1
    IdentityFile ~/.ssh/vm02

Host github github.com
    HostName github.com
    User git
    RequestTTY no
    IdentityFile ~/.ssh/github_sempernow

So, simply

# Session:
ssh vm02