1.打开终端App,输入如下代码,回车;
vi ~/.zshrc
或
vi ~/.bash_profile
打开 ~/.zshrc
/ ~/.bash_profile
后,滑至末尾另起一行,粘贴如下代码;
2.粘贴如下代码:(其中alias proxy的proxy与unproxy可以修改成你喜欢的代称);
alias proxy="
export http_proxy=socks5://127.0.0.1:1080;
export https_proxy=socks5://127.0.0.1:1080;
export all_proxy=socks5://127.0.0.1:1080;
export no_proxy=socks5://127.0.0.1:1080;
export HTTP_PROXY=socks5://127.0.0.1:1080;
export HTTPS_PROXY=socks5://127.0.0.1:1080;
export ALL_PROXY=socks5://127.0.0.1:1080;
export NO_PROXY=socks5://127.0.0.1:1080;"
alias unproxy="
unset http_proxy;
unset https_proxy;
unset all_proxy;
unset no_proxy;
unset HTTP_PROXY;
unset HTTPS_PROXY;
unset ALL_PROXY;
unset NO_PROXY"
粘贴成功后,确保处于终端App窗口且已激活当前窗口;按键盘左上角 esc,输入法切换至英文(abc)模式,输入 :wq!
,回车;(跟Linux 终端命令行一模一样...)
3.使用 .zshrc
source ~/.zshrc
或
source ~/.bash_profile
4.测试 proxy 效果
curl https://ip.cn
>> {"country": "广东省深圳市", "city": "电信"}
proxy
curl https://ip.cn # 注意不要 sudo
>> {"country": "美国", "city": "Choopa"}
5.取消代理
unproxy
如果不需要使用代理,则可执行上述命令;