由于macOS 10.11之后有SIP安全机制,已经不能够用一条简单的命令来解决,所以在不关闭SIP的情况下设置终端代理或者使用proxychains-ng之类的情况下就比较麻烦了,并且macOS终端也不支持socks5代理,只有配置http/https代理了,只有借助privoxy这个软件了。
一、安装并配置privoxy
brew install privoxy
vim /usr/local/etc/privoxy/config 在文件末尾输入:
listen-address 0.0.0.0:8118 # 8118是privoxy默认的监听端口
forward-socks5 / localhost:1080 . # 1080是本机配置的socks代理端口,后面有个.
意思就是说把本机的1080端口监听的socks流量转化成8118端口的http/https流量
brew services start privoxy 或者
sudo /usr/local/sbin/privoxy /usr/local/etc/privoxy/config 上方法关闭可以用kill ID
brew services stop privoxy
brew services restart privoxy
ps -ef | grep privoxy
telnet 127.0.0.1 8118
telnet 127.0.0.1 1080
二、在macOS终端配置
我的机器是/bin/bash 和 /bin/zsh 共存,目前我是在.zshrc里面配置了source ~/.bash_profile
所以我直接在.bash_profile里面配置以下内容即可:
function tproxy_on() {
export http_proxy='http://localhost:8118' && export https_proxy='http://localhost:8118'
curl cip.cc
}
function tproxy_off() {
unset http_proxy && unset https_proxy
curl cip.cc
}
source ~/.bash_profile
source ~/.zshrc
可以使用tproxy_on开机终端代理 tproxy_off关闭终端优惠
三、至此可以愉快的使用终端代理了