Mac 为终端设置代理

4,857 阅读1分钟

编辑 ~/.bash_profile 文件,没有则创建一个

如果终端是 zsh,那么编辑 ~/.zshrc

设置 http 和 https 代理

function proxy_on() {
    export http_proxy=http://127.0.0.1:7890;
    export https_proxy=http://127.0.0.1:7890;
    export no_proxy=localhost,127.0.0.1,localaddress,.localdomain.com;
    echo -e "已开启代理"
}

function proxy_off() {
    unset http_proxy;
    unset https_proxy;
    unset no_proxy;
    echo -e "已关闭代理"
}

function proxy_status() {
    echo $https_proxy
    curl cip.cc
}

其他代理设置

# ftp代理
export ftp_proxy=socks5://127.0.0.1:7890;
# rsync代理
export rsync_proxy=socks5://127.0.0.1:7890;
# 设置所有代理
export all_proxy=socks5://127.0.0.1:7890;

启动代理

proxy_on

关闭代理

proxy_off

测试代理是否生效

curl ip.sb
proxy_status