使用proxychain4進(jìn)行終端代理
引言(introduction)
在日常工作生活中,經(jīng)常遇到使用 wget或者 git時(shí),下載文件且文件在國內(nèi)下載慢甚至不能下載的情況,需要在終端使用代理。發(fā)現(xiàn)proxychains很方便好用。
proxychains
我們可以從github倉庫看到關(guān)于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
網(wǎng)上有些博文寫的 proxychains4 用
/etc/proxychains4.conf。
當(dāng)然是可以的,但就直接/etc/proxychains.conf也會(huì)生效。
甚至兩個(gè)文件都存在的時(shí)候proxychains.conf的優(yōu)先級(jí)比proxychains4.conf高。
中間都不用管,直接拉到最后:
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
#socks4 127.0.0.1 9050
socks5 [子網(wǎng)IP] [socket端口]
測試
$ curl www.httpbin.org/ip
$ proxychains4 curl www.httpbin.org/ip
接口返回的兩個(gè)本機(jī)IP不一致,說明開啟代理成功了。
使用
例如使用git克隆一個(gè)較大的倉庫,在原本輸入的命令前加入proxychain4即可
? proxychains4 git clone https://github.com/haad/proxychains.git