windows 直接下载 ss 终端,稍加设置即可完成全局代理,linux 用户如果需要让某个软件可以使用 ss 一般都需要连接端口才行。例如本地 ss 配置为:

1
2
"server_port":1800,
"local_port":1080,

原理简述

这边就相当于将本地的 127.0.0.1:1080 和 server_ip:1800 建立了连接关系。因此软件如果需要使用 vps 上面搭建的 ss 服务的话,则需要让该软件使用的协议连接到 127.0.0.1:1080 上。之前在 vps-shadowsocks 中介绍的 chrome 插件 SwitchyOmega 就是使用 SOCKS5 协议连接到 127.0.0.1:1080 上,让所有数据通过 SOCKS5 协议,然后从 127.0.0.1:1080 进行收发。

可以看出如果我们需要让其他软件也能够使用 ss 则需要让他们也能够使用 127.0.0.1:1080 代理服务器,然而不幸的是,大多数软件并不支持代理服务的功能, windows 平台下的软件很多可以通过设置 IE 代理让其他软件使用代理服务(原理是:大多数软件都会优先读取 IE 的代理设置,再访问网络)。

安装步骤

linux 下有个软件: proxychains 解决了我们的所有问题,该软件可以通过 sudo apt-get install proxychains 下载安装,一般为 3.1 版本。当然也可以去下载安装源码,源码安装版本较新,需要自行编译安装,一般为 4.x 版本。

配置

man proxychains 我们可以看到 proxychains 读取的配置文件地址,这边我们自定义 ~/.proxychains/proxychains.conf 文件,写入如下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ins.conf VER 3.1
#
# HTTP, SOCKS4, SOCKS5 tunneling proxifier with DNS.
#
# The option below identifies how the ProxyList is treated.
# only one option should be uncommented at time,
# otherwise the last appearing option will be accepted
#
#dynamic_chain
#
# Dynamic - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# at least one proxy must be online to play in chain
# (dead proxies are skipped)
# otherwise EINTR is returned to the app
#
strict_chain
#
# Strict - Each connection will be done via chained proxies
# all proxies chained in the order as they appear in the list
# all proxies must be online to play in chain
# otherwise EINTR is returned to the app
#
#random_chain
#
# Random - Each connection will be done via random proxy
# (or proxy chain, see chain_len) from the list.
# this option is good to test your IDS :)
# Make sense only if random_chain
#chain_len = 2
# Quiet mode (no output from library)
#quiet_mode
# Proxy DNS requests - no leak for DNS data
proxy_dns
# Some timeouts in milliseconds
tcp_read_time_out 15000
tcp_connect_time_out 8000
# ProxyList format
# type host port [user pass]
# (values separated by 'tab' or 'blank')
#
#
# Examples:
#
# socks5192.168.67.781080lamersecret
# http192.168.89.38080justuhidden
# socks4192.168.1.491080
# http192.168.39.938080
#
#
# proxy types: http, socks4, socks5
# ( auth types supported: "basic"-http "user/pass"-socks )
#
[ProxyList]
# add proxy here ...
# meanwile
# defaults set to "tor"
socks5 127.0.0.1 1080

使用

  • 输入 proxychains curl www.google.com 命令,我们可以看到提示内容,如果一直等待或者无法访问则代表设置失败。这是一种方法通过 proxychains + 命令。

这边值得注意的是使用 proxychains curl www.google.com 命令,博主一开始使用的是 proxychains ping www.google.com 一直无法 ping 通,也一致认为自己配置的有问题,后来才发现: ping 命令本身不调用 http ,socks5 等协议,ping也属于一个通信协议,是 TCP/IP 协议的一部分。而诸如: http ,socks5,ssh 等都是基于 TCP/IP 或者 UPD 之上的协议,所以验证的时候一定要当心注意了使用其他调用 socks5 协议的软件才可以验证。

  • 输入 proxychains bash 我们可以建立一个新的 shell 基于这个 shell 运行的所有命令和软件都会通过 127.0.0.1:1080 转发数据。

通过 proxychains 打开的软件,在使用时都会有详细的网络连接信息。

补充一个问题:如果使用时出现 ERROR: ld.so: object 'libproxychains.so.3' from LD_PRELOAD cannot be preloaded: ignored. 原因是无法找到 libproxychains.so.3 文件,可以通过 find /usr/lib/ -name libproxychains.so.3 找到具体路径,然后 export LD_PRELOAD=你找到的路径

全局代理

基于 proxychains bash 开启的所有软件都可以通过 ss 来访问外网,而这个 terminal 可以相当于是全局代理的,当然如果你需要设置整个系统都全局代理的话,应该也是可以修改 linux 下面的源码的,让密码认证通过后,启用的 login-bash 采用 proxychains 方式启用。这边未做详细研究,理论上可能可行。


个人对网络研究很欠缺,如有错误还望指正。

参考链接:
http://www.tuicool.com/articles/rUNFF3
http://askubuntu.com/questions/293649/proxychains-ld-preload-cannot-be-preloaded
http://blog.csdn.net/yusiguyuan/article/details/24269129