wsl 连接主机的代理

2023-03-11
-
-
 vim ~/.bash_profile

需要修改对应的代理端口

export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*') #获得网关地址
export proxyPort=1080 #端口
alias proxy='
    export https_proxy="http://${hostip}:${proxyPort}";
    export http_proxy="http://${hostip}:${proxyPort}";
    export all_proxy="http://${hostip}:${proxyPort}";
    echo -e "Acquire::http::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
    echo -e "Acquire::https::Proxy \"http://${hostip}:${proxyPort}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias unproxy='
    unset https_proxy;
    unset http_proxy;
    unset all_proxy;
    sudo sed -i -e "/Acquire::http::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
    sudo sed -i -e "/Acquire::https::Proxy/d" /etc/apt/apt.conf.d/proxy.conf;
'
source ~/.profile #加载环境
proxy #执行函数 代理生效

“您的支持是我持续分享的动力”

微信收款码
微信
支付宝收款码
支付宝

黄金_shmaur
不积跬步,无以至千里;不积小流,无以成江海
目录关闭