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:
Mine is 192.168.56.1
LAN.
We need to fix our VM a valid IP that fall into this network, i.e., 192.168.56.XXX
.
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 enp0s8
.
The interface is down by default , we need to bring it up.
Then we fix the ip
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!
Appendix
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.
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
or if you’re a bit lazy you can delete it all