SSH to VirtualBox Port Forwarding from WSL2 Machine

DevOps Jul 6, 2023

Step 1 VirtualBox: Configuration of Port Forwarding

If you’re familiar with this skip to the next Section

Setting > Network > Adapter 1

Expand Advanced > Click Port Forwarding

Add the port:

  • Host Port: Port you want to connect
  • Guest Port: default SSH as 22

Step 2: Connect from WSL2

First, we cannot naively connect to the localhost from WSL

The network is not mapped back like that.

We will need to find the IP of the host by

cat /etc/resolv.conf

References:
https://docs.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip

Now we’ve got the IP, in my case, 172.29.112.1

We SSH to that IP

Hope this help.

See you in the next article!

Tags

TeamCMD

We are CODEMONDAY team and provide a variety of content about Business , technology, and Programming. Let's enjoy it with us.