How to find WSL2 machine's IP address from windows
Solution 1:
From Windows powershell or cmd use the command:
wsl hostname -I
This should return an IP address if WSL is running. It appears to start the default distro if not running, and then return the address of that. (takes a few seconds longer to return)
Solution 2:
For me my WSL has multiple interfaces so hostname
isnt appropriate. In this instance you can use this:
wsl -- ip -o -4 -json addr list eth0 `
| ConvertFrom-Json `
| %{ $_.addr_info.local } `
| ?{ $_ }
Change -4
to -6
for ipv6, and eth0
to your interface of choice.