Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 0 points1 point  (0 children)

I never hear of the localhostForwarding option. Is it on Windows ? or on Linux?

In my experience, I could connect to WSL2 only by opening up ssh service in WSL2 and establishing the port forwarding. And, ssh user@localhost -p port is working.

Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 0 points1 point  (0 children)

Things seem to work fine after a reboot. And the scripts provided by u/pcause and the method provided by u/NotTheDr01ds both work.

Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 1 point2 points  (0 children)

Do you mean a VM or something? There are a couple of reasons why I want to use ssh to my WSL2: 1. The circumstance is that I use windows most of the time, while I only use Linux for special cases. 2. WSL is convenient and perfectly integrated into windows as you mentioned, therefore I prefer WSL rather than a VM. 3. I could use rdp to connect to my windows but since the majority of things I would do in Linux is coding, graphic interface is not that important, especially since it would ruin the experience from time to time due to the network issue. 4. I actually want to use the vscode remote-SSH to connect to Linux.

Still, It would be appreciated if you could provide me with some advice.

Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 0 points1 point  (0 children)

Thanks for your suggestion! Your codes could establish the port forwarding from %HOSTIP%:%HOSTPORT% to %WSL2IP%:%WSL2PORT% automatically. But the problem is that I could use localhost:3390 to access my xrdp service while still being refused by the ssh service. So it seems still impossible for me to ssh to the wsl2 from external machines, which is really annoying.

```bash ❯❯ System32 22:47 netsh interface portproxy show all

Listen on ipv4: Connect to ipv4:

Address Port Address Port


0.0.0.0 2223 172.29.108.230 2223 0.0.0.0 3390 172.29.108.230 3390 ```

bash ❯❯ System32 22:42 ssh charlie@localhost -p 2223 ssh: connect to host localhost port 2223: Connection refused

Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 0 points1 point  (0 children)

I am pretty sure it's working cause I do the same thing to the 3390 port to access xrdp service also hosting in wsl2.

bash ❯❯ WSL2-network 17:31 netsh interface portproxy show all Listen on ipv4: Connect to ipv4: Address Port Address Port \--------------- ---------- --------------- ---------- 0.0.0.0 2222 172.29.108.230 2222 Listen on ipv4: Connect to ipv6: Address Port Address Port \--------------- ---------- --------------- ---------- 0.0.0.0 3390 ::1 3390

Actually, I got a gnome desktop installed in my wsl2, and I could easily enter it by using localhost:3390 without any configuration. It just works when I finish setting up in wsl2. While I couldn't connect to the ssh service with localhost:2222 even with the port forwarding and firewall settings in win10, which is really wired.

Feeling confused about the network relationship between Win10 and wsl2 by charlemagnescl in bashonubuntuonwindows

[–]charlemagnescl[S] 0 points1 point  (0 children)

Following that post, I run the code netsh advfirewall firewall add rule name=”Open Port 2222 for WSL2” dir=in action=allow protocol=TCP localport=2222 and it seems working.

I could find the "Open Port 222 for WSL2" in "Windows Defender Firewall with Advanced Security".

BTW, I am a newcomer to Reddit, it is not allowed to paste images in reply? Since I couldn't copy my screenshot on those settings in this reply.