介绍

  Linux 服务器 CLI 操作环境,经常会使用一些指令访问境外的一些资源与服务。但是因为不可描述的原因,导致连接速度缓慢或者干脆无法建立连接。遇到这种情况而手里又有科学上网工具时,那么搭配使用 ProxyChains 就可以解决这个问题了。

ProxyChains is a UNIX program, that hooks network-related libc functions in DYNAMICALLY LINKED programs via a preloaded DLL (dlsym(), LD_PRELOAD) and redirects the connections through SOCKS or HTTP proxies. It supports TCP only (no UDP/ICMP etc).

准备

安装工具

yum install -y git gcc glibc-headers kernel-headers

下载源码

方法1

git clone https://github.com/rofl0r/proxychains-ng.git

方法2

如果访问不了 Github 或异常缓慢,可以先科学上网下载好源码包,然后再上传到服务器。

https://github.com/rofl0r/proxychains-ng/archive/master.zip

yum install -y unzip; unzip proxychains-ng-master.zip
mv proxychains-ng-master proxychains-ng

编译安装

cd proxychains-ng
./configure --prefix=/usr/local/proxychains --sysconfdir=/etc
make && make install

Debian:
apt install -y proxychains4

增加别名

vi ~/.bashrc

在 ~/.bashrc 中插入如下行

alias proxychains='/usr/local/proxychains/bin/proxychains4'

Debian:
alias proxychains='/usr/bin/proxychains4'

重载一下
source ~/.bashrc

修改配置

cp /root/proxychains-ng/src/proxychains.conf /etc/proxychains.conf

vi /etc/proxychains.conf

修改最后一行代理服务器的类型、地址与端口,例如:

socks5 172.16.0.196 1080

使用方法

在需要执行的指令前加上 proxychains,例如
proxychains curl https://www.google.com

BTW. ProxyChains 不支持 UDP 与 ICMP 协议。

卸载

删除程序目录与配置文件

rm -rf /usr/local/proxychains
rm -f /etc/proxychains.conf

删除别名 vi ~/.bashrc

删除如下行

alias proxychains='/usr/local/proxychains/bin/proxychains4'