A new experimental feature was added by Microsoft that will resolve this issue in the future. You will need to update to Windows Insider Build for Windows 10 or latest Windows 11 and update WSL. More info here.
On WSL1
we can access windows services running on localhost
ports directly, but when WSL2
was introduced things started breaking. One of those issue is access to windows localhost ports [^1]
To understand this issue we need to learn what is WSL2:
- WSL2 is a Managed Virtual Machine Running on Windows contrary to WSL1.
- Windows implements a virtual NIC for WSL2 thus the distro's host ip is different from the Windows host ip. [^2]