使用proxychain4进行终端代理
引言(introduction)
在日常工作生活中,经常遇到使用 wget
或者 git
时,下载文件且文件在国内下载慢甚至不能下载的情况,需要在终端使用代理。发现proxychains很方便好用。
proxychains
我们可以从github仓库看到关于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 SOCKS4a/5 or HTTP proxies.
It supports TCP only (no UDP/ICMP etc).
The way it works is basically a HACK; so it is possible that it doesn't work with your program, especially when it's a script, or starts numerous processes like background daemons or uses dlopen() to load "modules" (bug in glibc dynlinker).
It should work with simple compiled (C/C++) dynamically linked programs though.
If your program doesn't work with proxychains, consider using an iptables based solution instead; this is much more robust.
Supported Platforms: Linux, BSD, Mac, Haiku.
安装
sudo apt install proxychains4
配置
vim /etc/proxychains4.conf
网上有些博文写的 proxychains4 用
/etc/proxychains4.conf
。
当然是可以的,但就直接/etc/proxychains.conf
也会生效。
甚至两个文件都存在的时候proxychains.conf
的优先级比proxychains4.conf
高。
中间都不用管,直接拉到最后:
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
#socks4 127.0.0.1 9050
socks5 [子网IP] [socket端口]
测试
$ curl www.httpbin.org/ip
$ proxychains4 curl www.httpbin.org/ip
接口返回的两个本机IP不一致,说明开启代理成功了。
使用
例如使用git克隆一个较大的仓库,在原本输入的命令前加入proxychain4即可
❯ proxychains4 git clone https://github.com/haad/proxychains.git