For WSL2, the ip address of a running distro is not static, neither the subset WSL2 uses is fixed. If you need to do something like accessing the services on the WSL2 host, you need to get the address by yourself.
Get the ip address the current running distro:
ip -4 -br route get 8.8.8.8 | head -n 1|awk '{print $7}'
Get the ip address the host(the gateway):
ip -4 -br route get 8.8.8.8 | head -n 1|awk '{print $3}'
And get the netmask:
ifconfig eth0 |grep netmask|awk '{print $4}'
Top comments (0)