I remember needing this on a train ride, where I could not SSH into my machine without Wi-Fi. I'll explain the steps I used to configure this on my VirtualBox running on a Windows 10 host. Three things may be needed:
Add a Host-Only Network in VirtualBox.
Add a new adapter in the Virtual Machine and connect it to the
Host-Only Network.
Configure the new network adapter to get an IP address.
Add a Host-Only Network
In VirtualBox 6.1 I created a Host Network in the UI by going to File > Host Network Manager. See the Oracle documentation for more. I ticked the options to configure the adapter automatically and enable the DHCP server.
Add a New Adapter to the VM and Connect to the Host-Only Network
My VM only had one adapter enabled. In the VM network settings I went to Adapter 2 tab and ticked "Enable Network Adapter" then selected "Attached to: Host-only Adapter" and "Name: VirtualBox Host-Only Ethernet Adapter". This may be different in your UI. Now if I run ip a (shortcut for ip address) I can see the new adapter as enp0s8. The first one is still there, as enp0s3.
Configure the Network Adapter in The VM
My adapter showed up as being DOWN so the first thing I did was to bring it UP:
sudo ip link set enp0s8 up
Still, ip a showed no IP address, despite the interface being up. This means it's not automatically using DHCP and I have to configure it to do so. See below what I did on my Ubuntu system. It may be different for your distribution or if you want a static IP instead.
Added the following two lines to /etc/netplan/00-installer-config.yaml:
enp0s8:
dhcp4: true
So it now looks like this:
network:
ethernets:
enp0s3:
dhcp4: true
enp0s8:
dhcp4: true
version: 2
This was followed by:
sudo netplan --debug generate
sudo systemctl restart systemd-networkd
After this I could see the IP address on the enp0s8 interface with ip a and I can use it to SSH into my virtual machine from Windows Terminal, even in airplane mode!
Troubleshooting: I have found that this solution is not very stable. Sometimes I can still ping the VM from the host using the bridged adapter IP but not the host-only network IP. Restarting the interface, the VM or even virtualbox, etc. didn't fix anything, but the cliché of restarting Windows restored the functionality. My suggestion is, if this stops working, restart Windows first.