Mac 终端开启和关闭代理的方法
代理地址和端口可在代理工具中查看:
例 HTTP:127.0.0.1:10887
例 SOCKS5:127.0.0.1:10886
简单命令:临时使用
开启代理很简单,就是用 export 命令设置全局变量 http_proxy 和 https_proxy:
export http_proxy="http://127.0.0.1:10887" export https_proxy="http://127.0.0.1:10887"
关闭代理就是用 unset 命令把全局变量清空:
unset http_proxy unset https_proxy
自定义命令:预先设置并调用
创建文件
在你的用户根目录新建一个 .command 文件夹
创建2个文件:openproxy.sh closeproxy.sh
openproxy.sh
export http_proxy="http://127.0.0.1:10887" export https_proxy="http://127.0.0.1:10887" echo "already open proxy with 127.0.0.1:10887
closeproxy.sh
unset http_proxy unset https_proxy echo "already close proxy"
添加别名(alias)命令
修改你的 .bzshrc 或者 .zshrc 添加别名(alias)命令:
alias openproxy="source ~/.command/openproxy.sh" alias closeproxy="source ~/.command/closeproxy.sh"
使用方法:在终端直接输入命令
开启:openproxy
关闭:closeproxy