Reaching a service on Windows from inside WSL — sometimes localhost works, sometimes it does not, and I cannot see the pattern Networking
Running a database on Windows and an application inside the distro. Connecting to localhost from Linux works on my desktop and fails on my laptop, same setup as far as I can tell.
The other direction — a server inside Linux, browser on Windows at localhost — works reliably on both machines.
So the asymmetry is real and I would like the model rather than a workaround I do not understand:
- Why is one direction reliable and the other not?
- What address should Linux actually use to reach Windows?
- Why would two machines behave differently with the same versions?
@hyperv_hakan · 3h ago
For question 2, use the address the distro already knows, rather than
localhost. Inside Linux:That gives the gateway, which is the Windows host on the virtual network. It changes on every restart, which is exactly why hardcoding it into a config is a bad afternoon.
So do not hardcode it. Options in order of how well they hold up:
$(hostname).localif your setup provides it.wslconfig:Mirrored mode makes the distro share the host's network interfaces, so
localhostgenuinely means the same thing on both sides in both directions. It is the real fix for your problem rather than a workaround, and it also tends to survive VPNs, which the shim does not.Reply
Report