WSL: WSL2 cannot connect to Windows Host as a server

Please use the following bug reporting template to help produce issues which are actionable and reproducible, including all command-line steps necessary to induce the failure condition. Please fill out all the fields! Issues with missing or incomplete issue templates will be closed.

If you have a feature request, please post to the UserVoice.

If this is a console issue (a problem with layout, rendering, colors, etc.), please post to the console issue tracker.

Important: Do not open GitHub issues for Windows crashes (BSODs) or security issues. Please direct all Windows crashes and security issues to secure@microsoft.com. Ideally, please configure your machine to capture minidumps, repro the issue, and send the minidump from "C:\Windows\minidump".

Please fill out the below information:

  • Your Windows build number: (Type ver at a Windows Command Prompt) Microsoft Windows [Version 10.0.18932.1000]

  • What you’re doing and what’s happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)

  1. Start any server program, e.g. sql server, postgres, or a simple django program with runserver from the windows host.
  2. Bind the server program with the windows host IP address (vEthernet - WSL).
  3. Try to connect to the server program using the windows host IP address from WSL2.

Will get a timeout. Even trying to ping the windows host IP doesnt work - although traceroute www.google.com would successfully find a route.

  • What’s wrong / what should be happening instead: See above.

  • Strace of the failing command, if applicable: (If some_command is failing, then run strace -o some_command.strace -f some_command some_args, and link the contents of some_command.strace in a gist here). N/A

  • For WSL launch issues, please collect detailed logs.

See our contributing instructions for assistance.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 14
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I’m getting the same issue! In my case I’m running minikube in windows 10 pro and trying to access it from WSL 2 kubectl … Please help!

Tried without wirewall and it still doesn’t work!

Doesn’t work for me, tried to disable firewall, still got connection timed out error

So, I got it fixed. I just needed to add the port I’m trying to access on the host to the firewall.

I struggled with this for a while, but ended up managing to get it.

First, setting the host to listen on 0.0.0.0 (or your network interface’s IP address. if you go to cmd and type ipconfig you can find your interface IP address there) Second, Adding the Windows Firewall rule for the port you’re trying to access. Third, and this one caught me for a while. Edit that rule you’ve just created and make sure Advanced->Edge Traversal is enabled. Fourth, the address you need to connect to within wsl2 needs to be your interface’s IP address (the one found from ipconfig) and not localhost or 127.0.0.1.

The third point especially I hadn’t seen elsewhere, but was the last step needed for mine to work. Hopefully this helps!

Referring to this post in another thread. https://github.com/microsoft/WSL/issues/4150#issuecomment-504209723

This is an ok workaround for me, where I needed to connect to SQL server on host computer from WSL2. AFAIK Microsoft is still working on a permanent fix to forward localhost in WSL to host machine.

This is the script that I run on boot

$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';

if( $found ){
  $remoteport = $matches[0];
} else{
  echo "The Script Exited, the ip address of WSL 2 cannot be found";
  exit;
}

#[Ports]

#All the ports you want to forward separated by coma
$ports=@(1433);


#[Static ip]
#You can change the addr to your ip config to listen to a specific address
#Use the IP from Ethernet adapter vEthernet (WSL) or 0.0.0.0 if bind to any
$addr='0.0.0.0';
$ports_a = $ports -join ",";


#Remove Firewall Exception Rules
iex "Remove-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' ";

#adding Exception Rules for inbound and outbound Rules
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Outbound -LocalPort $ports_a -Action Allow -Protocol TCP";
iex "New-NetFireWallRule -DisplayName 'WSL 2 Firewall Unlock' -Direction Inbound -LocalPort $ports_a -Action Allow -Protocol TCP";

for( $i = 0; $i -lt $ports.length; $i++ ){
  $port = $ports[$i];
  iex "netsh interface portproxy delete v4tov4 listenport=$port listenaddress=$addr";
  iex "netsh interface portproxy add v4tov4 listenport=$port listenaddress=$addr connectport=$port connectaddress=$remoteport";
}

I then connect to the IPv4 address from Ethernet adapter vEthernet (WSL) in Windows from my application in WSL.

I’m still seeing this - even if I disable the firewall entirely.

If I use the wireless network’s address and bind to that interface on windows I can access it from wsl2 through that network, but I want to be able to do it through the local network between the wsl2 guest and the windows host rather than open up a public port.

This is despite seeing this on the windows host routes:

172.24.48.0    255.255.240.0         On-link       172.24.48.1    271

And this on the linux host routes:

172.24.48.0     0.0.0.0         255.255.240.0   U     0      0        0 eth0

So logically they should both be on the same network, but seemingly traffic can only flow in one direction.