I basically avoided this issue by using WSL1 for the past years, but I found a solution that works for me; If you don't encounter this issue often just use $(hostname).local 😒
TLDR; This changes localhost
to point to your Windows IP, 127.0.0.1
is still available for wsl. In windows you can access WSL via localhost
as usual, because windows listens for exposed ports on WSL. Exposes your set windows port(s) via portproxies
.
- Add this to your
/etc/wsl.conf
,
[boot]
command="sed -i \"s/127.0.0.1$(printf '\t')localhost/$(tail -1 /etc/resolv.conf | cut -d' ' -f2)$(printf '\t')localhost/g\" /etc/hosts 2>&1"