SSH to VirtualBox Host-Only Adapter Interface from WSL2 Machine
Alternative to Port Forwarding method I wrote here, there are popular host-only method.
Step 1: Add Another Adapter as ‘Host-only’
Setting > Network > Adapter 2
Select drop down choose “Host-only Adapter”.
Step 2: Fix IP to the VM
Now we have new network adapter.
Check on Host machine
In the host machine, in my case Window, you must see the interface like below:
We need to fix our VM a valid IP that fall into this network, i.e.,
Now we go to the VM
We will turn on the network adapter and fix the IP.
Check the network adapter with:
Your adapter recently added is show at the bottom. Mine is
The interface is down by default , we need to bring it up.
sudo ip link set enp0s8 up
Then we fix the ip
sudo ip addr add 192.168.56.11/24 dev enp0s8
Now check with
You must see the IP in the
inet section like below
Now it is working.
Step 3: Connect from WSL2
It is great that Host-only network is bridged to WSL2 by default.
Now we can directly connect to it without any forwarding. Good!
Here we go!
If you come from other source on the internet, you might find the following differences:
Note: interface file
The file in the below folder is not available in Ubuntu 18.04 + anymore
They move to use https://netplan.io/. So we ignore this.
Note: ifup is not found
The command like below is not valid anymore.
sudo ifup enp0s8
You need to install extra library but recommend to use
ip command like above tutorial
Note: IP Command
If you insert the wrong IP, you can delete it by
sudo ip addr del 192.168.56.11/24 dev enp0s8
or if you’re a bit lazy you can delete it all
sudo ip addr flush dev enp0s8