安装proxychains
简单粗暴的方式:
$ sudo apt-get install proxychains
如果想要使用最新版,也可以自己手动编译源码
# 安装
git clone https://github.com/rofl0r/proxychains-ng.git
./configure --prefix=/usr --sysconfdir=/etc
make
sudo make install
sudo make install-config
配置
在安装完成之后,一般在 /etc/proxychains.conf 处会有默认配置文件,编辑该文件
sudo vim /etc/proxychains.conf
然后在文件末修改成自己设置的shadowsocks设置的端口,如下
socks5 127.0.0.1 1080
验证
$ curl ip.gs
这个显示的ip是没有被代理的
$ proxychains curl ip.gs
这个就是你的代理了
在配置完 proxychains 之后,在终端如果任何命令无法连接成功时,在其前加上 proxychains 就可以走代理方式来执行该命令。
shell函数(unix&linux)
如果系统不支持proxychains,可以考虑设置函数。
# .zshrc
# 标准代理环境变量
# function to enable terminal proxy
function set_proxy() {
# HTTPS proxy (recommended)
# export HTTPS_PROXY=https://proxy.example.com:8080
# HTTP proxy (if HTTPS not available)
# export HTTP_PROXY=http://proxy.example.com:8080
export HTTP_PROXY=http://127.0.0.1:10808
# export HTTP_PROXY=socks5://127.0.0.1:10808
export HTTPS_PROXY=$HTTP_PROXY
export ALL_PROXY=$http_proxy
echo -e "Proxy is ON"
}
# function to disable the terminal proxy
function unset_proxy(){
unset HTTP_PROXY HTTPS_PROXY ALL_PROXY
echo -e "Proxy is OFF"
}
# Bypass proxy for local server (required)
export NO_PROXY=localhost,127.0.0.1,::1