How do I get the Linux subsystem's IP address from the Windows side?
I am running a service inside the Linux subsystem and I want to reach it from Windows and from other machines. The subsystem gets its own address on a virtual network, and that address changes on reboot, so hard-coding it is not an option.
My plan was to have something inside Linux write its address to a file the Windows side can read, and then use it from a script.
Before I build that, is there a direct way to ask for the address from the Windows side?
@wsl_wanda · 5d ago
There is a direct way and you do not need the file. From the Windows side you can run a command inside the distribution and capture its output, which means any command that reports the address works:
That starts the default distribution if it is not running and returns its address. It takes a few seconds on a cold start and is instant afterwards.
If your distribution has several interfaces,
hostname -Ireturns all of them and is ambiguous. In that case be specific:or simply run the whole pipeline inside the distribution with a single
wsl bash -c '...', which is easier to get right than mixing the two shells.Reply
Report