介绍
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 或异常缓慢,可以先科学上网下载好源码包,然后再上传到服务器。
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'
版权声明:本文为原创文章,版权归 BenhoN 所有。
本文链接:https://blog.benhon.net/archives/proxychains.html
所有原创文章采用知识共享 署名-非商业性使用 4.0 国际 许可协议进行许可,你可以自由地转载和修改,但请务必注明文章来源并且不可用于商业目的。