Get the host address for WSL2
Li
Posted on March 3, 2023
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}'
💖 💪 🙅 🚩
Li
Posted on March 3, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.