How to get Ubuntu in WSL 2 to talk to an HTTP server on same Windows host

networkingwindows 10windows-subsystem-for-linux

I am running a console app in Windows 10 which has a self-hosted HTTPS server listening on port 44340. It's an ASP.NET Core website (Kestrel) and its perfectly browsable on the Windows side.

I cannot reach this port from within a Windows Subsystem for Linux 2 (WSL2) console running Ubuntu 18.04, testing with curl.

I've tried adding a Windows Firewall rule for that port but it doesn't seem to work.

I've tried via localhost, as well as the two IPs I can see for my machine. One is the real NIC using DHCP and the other is a vEthernet adapter for WSL with a 172.31 address.

Best Answer

Here's what I did.

  • Disabled the Windows Firewall (then once proven working, re-enabled and added a rule).
  • Add a hosts file entry on the Windows side for host xyz pointing at my physical NIC IP.
  • Created a self-signed certificate for xyz.
  • Configured Kestrel to listen on the physical NIC IP and load the certificate for xyz
  • Checked the Windows side worked with Chrome.
  • Launched WSL and pinged xyz.
  • Ran curl https://xyz:44340 and observed the failure to validate my self-signed cert.

That confirms TCP is working, so I'm off to bed. Essentially the blockers were:

  • Firewall.
  • Kestrel not listening on the right IP.
Related Topic