主机 IP,在 /etc/resolv.conf 中可以查看
cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " "
wsl2 在 .bashrc
设置全局变量
host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ")
wsl2 使用代理
export all_proxy="socks5://$host_ip:7890"
发现在我本机上,host.docker.internal
也可以作为 host 代替主机 IP 进行代理(暂不确定是不是需要 WSL2 集成 Docker)
root@PC:~# ping host.docker.internal
PING host.docker.internal (192.168.31.202) 56(84) bytes of data.
root@PC:~# ping $host_ip
PING 172.20.208.1 (172.20.208.1) 56(84) bytes of data.
WSL2 IP, 在 ifconfig 的 eth0 中可以看到
如果使用了别名 ip
导致无法使用 ip address
命令,可以使用 ifconfig
(例如我的情况,使用了 aliase 别名 alias ip='ifconfig'
时不能使用 ip address
)
ip address
ip address show eth0 | grep 'inet ' | awk '{ print $2; }' | sed 's/\/.*$//'
ifconfig
ifconfig eth0 | grep 'inet ' | awk '{ print $2; }' | sed 's/\/.*$//'
wsl2 在 .bashrc
设置全局变量
wsl2_ip=$(ifconfig eth0 | grep 'inet ' | awk '{ print $2; }' | sed 's/\/.*$//')