WSL 2 Networking
Why Stack Overflow recommends it
Stack Overflow users link it when they need to reach a server running in WSL2 from another machine or phone on the LAN, since it shows the netsh portproxy and firewall steps.
Recommended by 2 people across 2 different months, 2020 to 2024.
What it is
David Bombal explains how networking differs between WSL 1 and WSL 2 and how to make a WSL 2 virtual machine reachable from other devices. He walks through the Windows netsh portproxy command, the Windows Firewall rules needed, and a GitHub issue script, testing the connection from a Mac.
What people said
Recommends Akbar Pulatov · 2020-09 · Stack Overflow · on “Connecting to WSL2 server via local network”
See this video, it helped me: [this video] netsh interface portproxy add v4tov4 listenport=<port-to-listen> listenaddress=0.0.0.0 connectport=<port-to-forward> connectaddress=<forward-to-this-IP-address> for example netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=172.30.16.3 Microsoft has published a little bit of information about this on their WSL1 to WSL2 comparison page [LINK]
Recommends L.Le · 2022-12 · Stack Overflow · on “unable to access network from WSL2”
thank you so much for this! i love how it's not a script that needs to be ran after every reboot. works better for me than these two examples [LINK] and [this video]
Cites markvgti · 2021-07 · Stack Overflow · on “Connecting to server on WSL2 from Windows host doesn't work”
Update 1 If I package the code as a Docker image & run it, the curl commands work from inside WSL2 and from the Windows command line, so this is a Quarkus-specific issue. Original I have Ubuntu 20.04 installed on WSL2 on my Windows Home laptop. Following the Quarkus Getting Started [LINK] example (just up to step 5: Running the application ), I have the code (server) running on my WSL2 bash command line, & calling it with curl gives the expected output: user@computer:/path$ curl -w '\n' [LINK] Hello RESTEasy However, I can't access that server from the host Windows computer's command line ( cmd ): C:\Users\username>curl -w "\n" [LINK] curl: (56) Recv failure: Connection was reset Unlike this
Cites Howard Choi · 2022-01 · Stack Overflow · on “How to access Rpi via ssh to WSL2 in window 10”
I tried to access WSL2 from raspberry pi by ssh I watch this video clip however I can not [this video] First in Rpi to wsl2 ssh user@192.168.0.1 -p 3000 and wsl2 to Rpi in PowerShell netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=3000 connectaddress=192.168.240.40(wsl2) connectport=3000 and I fix the /etc/ssh/sshd_config Port 3000 ListenAddress 0.0.0.0 However, I got an error in Rpi --> ssh_exchange_identification: read: Connection reset by peer Do I have something wrong!
Cites Luca P. · 2022-06 · Stack Overflow · on “Accessing WSL2 Vue.js server (localhost:8080) exposing NATted IP number externally”
Some background, just so you know what I am trying to achieve before someone suggests that what I want is not what I want: I am developing a Vue.js 3 service, with a little Python (Flask) backend. Both components run on (Ubuntu) WSL2 and Windows 10. Everything has worked fine referring to [LINK] (Vue) and [LINK] (Flask) respectively (URLs work out of the box from my Chrome on Windows without further configuration). My problem is that I could also use exposing 8080 with the IP number on my LAN to test the UI I'm building with my phone (inspiration here [LINK] ). Trying to do this, in turn, lead me here [this video] and here [LINK] ). All good? Not so much, because: Ubuntu: $ lsb_release -a No LSB
Cites kiko carisse · 2023-12 · Stack Overflow · on “WSL-2: Which ports are automatically forwarded?”
Why is the port forwarding needed for wsl2? After I watched this [this video] , and read through this thread [LINK] , I learned that wsl1 used to just work, and port forwarding was not necessary; but beyond that I haven't gone too in far depth (something to do with wsl2 being hyper-v now). In any case, I created this powershell script, below, inspired by this famous script [LINK] . I was trying to port forward the Expo port, to be able to run my react native app on my physical android device by connecting to my windows pc's wifi network address. The port exposed by expo start --dev-client is 8081 so that is what is in the script below (but any port could be used). echo "Running WSL Port Forward S
Cites Null Salad · 2024-01 · Stack Overflow · on “How can you make a node server running on WSL2 forward over LAN so that it can be accessed by a phone?”
I've tried the following: [this video] [LINK] [LINK] [LINK] [LINK] [LINK] [LINK] [LINK] [LINK] They all share a common procedure: Create firewall exceptions for relevant ports in Admin PowerShell run: netsh interface portproxy add v4tov4 listenport=3001 listenaddress=0.0.0.0 connectport=3001 connectaddress=(wsl hostname -I) Find windows IPv4 address in PowerShell with ipconfig on mobile phone, connect to same wifi network go to <windows_IPv4_address>:3001 For good measure, in the Node.js Express app, I run: server.listen(PORT, '0.0.0.0', ()=> { console.log(`⚡️ listening on ${PORT}`); }) What happens: Accessing <windows_IPv4_address>:3001 , localhost:3001 , 0.0.0.0:3001 and 127.0.0.1 on my phone t
Cites nikto · 2024-12 · Stack Overflow · on “Cannot proxy port on WSL”
I'm currently trying to configure Cassandra in WSL but it cannot establish a connection ( ERROR: cannot bind to MY_PUBLIC_IP:7000 ). To solve this I did two things : I now have port redirection from my public IP to my local windows IP (using port 7000 and 9042) and I followed David Bombal's guide [this video] to have a port redirection from my local windows IP to my WSL2 IP. The command I used (for the second redirection) was netsh interface portproxy add v4tov4 listenport=7000 listenaddress=0.0.0.0 connectport=7000 connectaddress=MY_WSL_IP in PowerShell (I also tried listenaddress=MY_WINDOWS_PRIVATE_IP ). After those two changes, I did some networking tests using ncat . The results are as follow