在添加~/.bashrc中添加
# WSL2使用的是虚拟机技术和WSL第一版本不一样,和宿主windows不在同一个网络内
# 获取宿主windows的ip
export windows_host=`ipconfig.exe | grep -n4 WSL | tail -n 1 | awk -F":" '{ print $2 }' | sed 's/^[ \r\n\t]*//;s/[ \r\n\t]*$//'`
# 假设你的宿主windows代理端口是1080, 全面设置WSL内的代理
export ALL_PROXY=socks5://$windows_host:1080
export HTTP_PROXY=$ALL_PROXY
export http_proxy=$ALL_PROXY
export HTTPS_PROXY=$ALL_PROXY
export https_proxy=$ALL_PROXY
# 设置git的代理
if [ "`git config --global --get https.proxy`" != "socks5://$windows_host:1080" ]; then
git config --global https.proxy socks5://$windows_host:1080
fi
# wcd
# cd C:\\ 自动切换到 /mnt/c
function wcd() {
command cd `wslpath "$1"`
}
#设置docker内的代理
#在/etc/default/docker有
# export http_proxy="socks5://[windows_host]:1080"
# export https_proxy="socks5://[windows_host]:1080"
sudo sed -i -E "s#socks5.*?1080#socks5://$windows_host:1080#" /etc/default/docker
# 设置WSL内的DNS, 默认是系统自己创建的
sudo bash -c 'echo -e "\nnameserver 114.114.114.114\nnameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf'