关于wsl2:WSL2中cargo使用代理

3次阅读

共计 563 个字符,预计需要花费 2 分钟才能阅读完成。

在 WSL 应用 Cargo 时,会有须要用到外网的状况。假如咱们在 windows 开了一个端口为 10809 的 HTTP 代理。咱们的指标是让 WSL 中的 cargo build 应用到这个代理。

查看 WSL 拜访 windows 的 IP 地址

cat /etc/resolv.conf

能够看到相似的输入

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.22.96.1

其中的 nameserver 就是 windows 的 IP 地址,咱们能够将代理设置为http://172.22.96.1:10809,这样 WSL 就能够应用到架设在 windows 里的代理服务。

要留神到这个 IP 地址是不是会产生扭转,因为 WSL2 和代理服务不兼容的 BUG,咱们常常须要应用 netsh winsock reset 重置网络,这时候这个 IP 地址可能会发生变化,导致代理设置生效

失去 IP 地址后,关上 ~/.cargo/config.toml
写入以下字段

[http]
debug = true
proxy = "172.22.96.1:10809"
正文完
 0