介绍

在Linux服务器上,有些工具自带支持代理(proxy)的功能,而一些没有,或者说只支持http代理,不支持socks5。我们可以使用proxychains为这些工具提供代理。

最简单的栗子,使用 proxychains 通过ssh连接服务器的时候走 shadowsocks 的隧道,甚至国内的机器拉取不动github上面的代码时,也可以使用 proxychains 的。

安装

Debian系列

默认源里面有个 proxychains,版本是3.1

1
2
3
4
5
6
7
8
9
10
11
root@debian:~# apt search proxychains
Sorting... Done
Full Text Search... Done
libproxychains-dev/oldstable 3.1-6 amd64
proxy chains -- shared library (development)

libproxychains3/oldstable 3.1-6 amd64
proxy chains -- shared library (runtime)

proxychains/oldstable 3.1-6 all
proxy chains - redirect connections through proxy servers

安装:

1
apt install -y proxychains

如果你想安装proxychains4,可以按照以下:

  1. 安装依赖

    1
    apt install -y git gcc automake autoconf libtool make
  2. 克隆proxychains仓库并安装

    1
    2
    3
    4
    5
    git clone https://github.com/rofl0r/proxychains-ng.git
    cd proxychains-ng
    ./configure
    make && make install
    cp ./src/proxychains.conf /etc/proxychains.conf

CentOS

CentOS上,即使是安装epel-release源,也没有这个软件的,只能手动安装。
安装过程和Debian的差不多,只需把包管理工具改成yum即可。

  1. 安装必要依赖

    1
    yum install -y git gcc automake autoconf libtool make
  2. 克隆proxychains仓库并安装

    1
    2
    3
    4
    5
    git clone https://github.com/rofl0r/proxychains-ng.git
    cd proxychains-ng
    ./configure
    make && make install
    cp ./src/proxychains.conf /etc/proxychains.conf

配置

默认配置文件位于:/etc/proxychains.conf

这里默认常用的代理是shadowsocks
代理端地址 127.0.0.1 ,端口 1080

只需要在/etc/proxychains.conf文件中的最后一段
修改原有的为如下即可

1
2
3
4
5
6
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks5 127.0.0.1 1080

使用

如果要让一个命令走proxychains的代理,只需要在命令前加上proxychains4即可。

比如我们的栗子,使用proxychains通过ssh连接服务器的时候走shadowsocks的隧道。

1
proxychains4 ssh <server-ip>

这样就可以了。