Loading... > 转载自:https://www.cnblogs.com/BOHB-yunying/articles/12205099.html linux下代理一般是通过http_proxy和https_proxy这两个环境变量,但是很多软件并不使用这两个变量,导致流量无法走代理。 在不使用vpn的前提下,linux并没有转发所有流量的真全局代理。但是可以用proxychains-ng为程序指定走代 理,proxychains-ng是proxychains的加强版,主要有以下功能: 1. 支持http/https/socks4/socks5 2. 支持认证 3. 远端dns查询 4. 多种代理模式 不足: 1. 不支持udp/icmp转发 2. 少部分程序和在后台运行的可能无法代理 一、安装下载源码: <pre class="php hljs mCustomScrollbar _mCS_1 mCS-autoHide mCS_no_scrollbar" id="pre-pz5MSH"><div id="mCSB_1" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_1_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-PfhDdF">git <span class="hljs-keyword">clone</span> https:<span class="hljs-comment">//github.com/rofl0r/proxychains-ng</span> </code-pre></div></div></pre> 编译和安装: <pre class="prettyprint php hljs mCustomScrollbar _mCS_2 mCS-autoHide mCS_no_scrollbar" id="pre-YxWZab"><div id="mCSB_2" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_2_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-yTwnim">cd proxychains-ng ./configure --prefix=/usr --sysconfdir=/etc make make install make install-config cd .. && rm -rf proxychains-ng</code-pre></div></div></pre> 如果执行make && make install时提示make: cc: Command not found错误 这是由于新安装的Linux系统没有安装gcc环境,需要安装gcc <pre class="prettyprint php hljs mCustomScrollbar _mCS_3 mCS-autoHide mCS_no_scrollbar" id="pre-6nehdx"><div id="mCSB_3" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_3_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-RPwsjt">yum install gcc</code-pre></div></div></pre> 二、配置proxychains-ng的配置非常简单,只需将代理加入[ProxyList]中即可,贴一份配置: <pre class="prettyprint bash hljs mCustomScrollbar _mCS_4 mCS-autoHide mCS_no_scrollbar" id="pre-tPHTem"><div id="mCSB_4" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_4_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-44eBw5">dynamic_chain chain_len = 1 <span class="hljs-comment">#round_robin_chain和random_chain使用</span> proxy_dns remote_dns_subnet 224 tcp_read_time_out 15000 tcp_connect_time_out 8000 [ProxyList] socks5 127.0.0.1 1080 socks4 127.0.0.1 1081 http 127.0.0.1 3128 </code-pre></div></div></pre> proxychains-ng支持多种代理模式: * dynamic_chain :按照代理列表顺序自动选取可用代理 * strict_chain :按照代理列表顺序使用代理,所有代理必须可用 * round_robin_chain :轮询模式,自动跳过不可用代理 * random_chain :随机模式 三、测试 <pre class="undefined hljs css mCustomScrollbar _mCS_5 mCS-autoHide mCS_no_scrollbar" id="pre-QPs5rK"><div id="mCSB_5" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_5_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-fK2yAH"><span class="hljs-selector-tag">proxychains4</span> <span class="hljs-selector-tag">curl</span> <span class="hljs-selector-tag">ip</span><span class="hljs-selector-class">.cn</span> </code-pre></div></div></pre> 四、使用用法非常简单: <pre class="undefined hljs nginx mCustomScrollbar _mCS_6 mCS-autoHide mCS_no_scrollbar" id="pre-x5rDBi"><div id="mCSB_6" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_6_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-JrCNy8"><span class="hljs-attribute">proxychains4</span> 程序 参数 </code-pre></div></div></pre> 这样用每次都要在命令前输入proxychains4,比较麻烦,可以用proxychains4代理一个shell,在shell中执行的命令就会自动使用代理了,例如: <pre class="ruby hljs mCustomScrollbar _mCS_7 mCS-autoHide mCS_no_scrollbar" id="pre-icX8Qi"><div id="mCSB_7" class="mCustomScrollBox mCS-minimal-dark mCSB_vertical_horizontal mCSB_outside" tabindex="0"><div id="mCSB_7_container" class="mCSB_container mCS_y_hidden mCS_no_scrollbar_y mCS_x_hidden mCS_no_scrollbar_x" dir="ltr"><code-pre class="code-pre" id="pre-8EsGfB">proxychains4 -q /bin/bash </code-pre></div></div></pre> 这就有点像全局代理了 最后修改:2021 年 11 月 02 日 05 : 27 PM © 转载自他站 赞赏 要多恰饭才能长胖 赞赏作者 支付宝微信