7

Ubuntu安装proxychains,让终端命令使用socks5代理,加速下载资源,解决Could not res...

 3 years ago
source link: https://blog.popkx.com/Ubuntu-install-proxychains-let-terminal-using-socks5-proxy-speed-up-downloading/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Ubuntu安装proxychains,让终端命令使用socks5代理,加速下载资源,解决Could not resolve host错误,找不到'libproxychains.so.3' 库的错误

发表于 2020-01-04 23:01:00   |   已被 访问: 2,445 次   |   分类于:   Linux笔记   |   2 条评论

我的移动宽带在 clone 以及下载 GitHub 资源时,奇慢无比,常常只有几 kB,更难以忍受的是 Python 的 pip 命令安装包的速度也是非常的慢,甚至慢到“超时”,最终无法安装成功。正好前阵子使用C语言编写了一个socks5代理服务,在浏览器上可以成功的实现代理,因此探寻在 Linux 终端如何让命令也使用该 socks5 服务,实现 apt、pip、wget 等命令的加速。

安装 proxychains

搜索了一些资料,最后决定使用 proxychains 程序。在 Ubuntu 上安装它是非常简单的,只需要执行下面的命令即可:

$ sudo apt install tor
$ sudo apt install proxychains

完成后便可使用 proxychains 程序。

使用 proxychains

主要需要配置 /etc/proxychains.conf 文件,打开之,在[ProxyList]项添加 socks5 服务的 ip:port,如下图所示:

添加 socks5 服务的 ip:port

添加 socks5 服务的 ip:port

正如 proxychains 的名字所示,它是一个“代理链”,因此如果填写了多个代理,那么 proxychains 将会将这些代理组成链。

记得取消 proxy_dns,如下图所示:

否则在稍后的使用中,会出现类似于下面这样的错误:

$ proxychains curl baidu.com
ProxyChains-3.1 (http://proxychains.sf.net)
|DNS-request| baidu.com 
|S-chain|-<>-127.0.0.1:1080-<--timeout
|DNS-response|: baidu.com does not exist
curl: (6) Could not resolve host: baidu.com

配置完毕后,执行下面的命令尝试使用 proxychains:

$  proxychains ping baidu.com
ProxyChains-3.1 (http://proxychains.sf.net)
ERROR: ld.so: object 'libproxychains.so.3' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.

我这里又报错了,根据错误信息,是没有从 LD_PRELOAD 里找到 'libproxychains.so.3' 库。解决这个问题也很简单,我们先使用 which 命令查看 proxychains 所在目录:

$ which proxychains 
/usr/bin/proxychains

然后在 /usr 目录搜索'libproxychains.so.3' 库:

$ find /usr -name "libproxychains.so.3"
/usr/lib/x86_64-linux-gnu/libproxychains.so.3

接着便可打开 proxychains 文件:

$ sudo vim /usr/bin/proxychains

将上面搜索到的库路径填入:

修改 proxychains

修改 proxychains

经过上面的配置和修改,终于可以正常使用 proxychains 程序进行 Ubuntu 的终端命令 socks5 代理了,方法很简单,只需要在命令前加上 proxychains 即可,例如:

$ proxychains curl baidu.com
$ sudo proxychains pip install numpy
$ sudo proxychains apt install gcc

等。看到类似于下面这样的输出,即可表明 proxychains 正常连接到 socks5 服务了:

...
|S-chain|-<>-<server ip:port>-<><>-151.101.40.223:443-<><>-OK
|S-chain|-<>-<server ip:port>-<><>-151.101.0.223:443-<><>-OK
|S-chain|-<>-<server ip:port>-<><>-151.101.25.63:443-<><>-OK
...

在我实测中,的确可以通过 socks5 代理实现提速,例如原本只有几 kB 的下载速度,使用 proxychains 后,提速到几百 kB 了。

阅读更多:   Linux笔记


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK