情况
由于最近在中国某个地方爆发了 riot, 所以境内很多网站又是无法访问 (twitter.com、facebook.com 等),让我们这些网民很无奈。
使用 SSH
我 曾经介绍过 如何使用 SSH 来建立一个 SOCKS 代理服务器,让你能够在 Firefox 里正常访问以上所提起的网址。然而不是所有 Linux 软件都能支持代理服务器。如果你最热爱的 Linux 工具需要访问”被封”的网站,又没有嵌入的代理支持,该怎么办呢?
遇到这种情况当然不要放弃该软件… 毕竟我们用的系统是 Linux 而不是以前让我们咳声叹气,丧失信心的 Windows,总有一个方法去解决问题。
举个例子吧
我不久前发现了 Twitter 这个网站。我一开始不经常用,也搞不明白别人为什么对这个 web 2.0 服务都着了迷。后来我在推特上跟的人越来越多,跟着我的人亦是日益增多,不知不觉我也迷上了该网站,天天都会上。凡是经常用推特的人一般都会用一个推特的 客户端,这才能跟得上朋友们的状态更新和最火热的网络新闻。本人作为 Ubuntu 的用户,我自然就选了 Gwibber 这个基于 GNOME 的客户端来访问我的推特。这个软件功能很丰富,用起来得心应手,不过总有一个问题让我有点遗憾,就是 Gwibber 还不听从 GNOME 的代理设置 。 平时这也不是一个很大的问题,但是每遇中国网络封锁较严重时,都会让我暂时无法使用该软件。
解决方案… Tsocks
经过几个 Google 搜索,我最终很高兴地发现 Linux 有一个能够强迫任何软件通过 SOCKS 代理上网的工具,其名就是 tsocks。Tsocks 是一个透明 SOCKS 代理软件,只要你电脑有一个连 接到国外服务器的 SSH 隧道 ,你就能让任何软件。
安装并配置 Tsocks
以下说明都是为了那些使用 Ubuntu 的 Linux 用户,不过在别的 Linux 发行版下,安装的过程应该与此差不多。
在终端中:
sudo apt-get install tsocks
修改配置文件:
sudo nano /etc/tsocks.conf
将其内容改成以下几行并保存退出:
local = 192.168.1.0/255.255.255.0 #local表示本地的网络,也就是不使用socks代理的网络
server = 127.0.0.1 # SOCKS 服务器的 IP
server_type = 5 # SOCKS 服务版本
server_port = 9999 #SOCKS 服务使用的端口
你可能需要修改一下以上内容,用你自己的 SSH 隧道设置。
运行软件
用 tsocks 运行你的软件很简单,在终端中:
tsocks 你的软件 &
我现在运行 Gwibber 都是这样运行的:
tsocks gwibber &
祝你们愉快!
EDIT—————–>
我今天还发现了另外一个工具,其功能似乎比 tsocks 要更丰富,配置起来更简单,而且不会那么容易出错。这个工具就是 proxychains 。 以下有配置方法:
sudo apt-get install proxychains
修改配置文件 (/etc/proxychains.conf),应该如下:
# proxychains.conf VER 2.0
#
# HTTP, SOCKS4, SOCKS5 tunneling proxifier.
#
# 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 - 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 - 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 - Each connection will be done via random proxy
# (or proxy chain, see chain_len) from the list
# this option is good for scans
dynamic_chain
#strict_chain
#random_chain
# Make sense only if random_chain
chain_len = 2
# Quiet mode (no output)
#quiet_mode
# Write stats about good proxies to proxychains.stats
#write_stats
#Some timeouts in milliseconds
#
tcp_read_time_out 15000
tcp_connect_time_out 10000
[ProxyList]
# ProxyList format
# type host port [user pass]
# (values separated by 'tab' or 'blank')
#
#
# Examples:
#
# socks5 192.168.67.78 1080 lamer secret
# http 192.168.89.3 8080 justu hidden
# socks4 192.168.1.49 1080
# http 192.168.39.93 8080
#
#
# proxy types: http, socks4, socks5
# ( auth types supported: "basic"-http "user/pass"-socks )
#
#http 10.0.0.5 3128
socks5 127.0.0.1 9999
socks4 127.0.0.1 9050
注意事项:
- 要选 dynamic_chain 而不是 random_chain
- 可以列举几个代理服务器,proxychains 会按顺序用,代理无法访问即自动选用下一个
- 代理服务器要根据自己电脑的情况自行调整
运行 proxychains
运行 proxychains 跟运行 tsocks 完全一样。在终端中:
proxychains 你的软件 &
比如说:
proxychains chromium-browser &
我还是推荐你使用 proxychains!