<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sprayfly &#187; 翻墙</title>
	<atom:link href="http://sprayfly.com/tag/%e7%bf%bb%e5%a2%99/feed/" rel="self" type="application/rss+xml" />
	<link>http://sprayfly.com</link>
	<description>Languages, Linux, Life</description>
	<lastBuildDate>Wed, 14 Jul 2010 03:32:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>用 tsocks 和 proxychains 使 Linux 下所有软件能够翻墙</title>
		<link>http://sprayfly.com/2009/07/09/%e7%94%a8-tsocks-%e4%bd%bf-linux-%e4%b8%8b%e6%89%80%e6%9c%89%e8%bd%af%e4%bb%b6%e8%83%bd%e5%a4%9f%e7%bf%bb%e5%a2%99/</link>
		<comments>http://sprayfly.com/2009/07/09/%e7%94%a8-tsocks-%e4%bd%bf-linux-%e4%b8%8b%e6%89%80%e6%9c%89%e8%bd%af%e4%bb%b6%e8%83%bd%e5%a4%9f%e7%bf%bb%e5%a2%99/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 05:31:36 +0000</pubDate>
		<dc:creator>Jono</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[china]]></category>
		<category><![CDATA[翻墙]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[gfw]]></category>
		<category><![CDATA[gwibber]]></category>
		<category><![CDATA[proxychains]]></category>
		<category><![CDATA[SOCKS]]></category>
		<category><![CDATA[tsocks]]></category>
		<category><![CDATA[封锁]]></category>
		<category><![CDATA[封杀]]></category>

		<guid isPermaLink="false">http://sprayfly.com/?p=403</guid>
		<description><![CDATA[情况 由于最近在中国某个地方爆发了 riot, 所以境内很多网站又是无法访问 (twitter.com、facebook.com 等)，让我们这些网民很无奈。 使用 SSH 翻墙 我曾经介绍过如何使用 SSH 来建立一个 SOCKS 代理服务器，让你能够在 Firefox 里正常访问以上所提起的网址。然而不是所有 Linux 软件都能支持代理服务器。如果你最热爱的 Linux 工具需要访问&#8221;被封&#8221;的网站，又没有嵌入的代理支持，该怎么办呢？ 遇到这种情况当然不要放弃该软件&#8230; 毕竟我们用的系统是 Linux 而不是以前让我们咳声叹气，丧失信心的 Windows，总有一个方法去解决问题。 举个例子吧 我不久前发现了 Twitter 这个网站。我一开始不经常用，也搞不明白别人为什么对这个 web 2.0 服务都着了迷。后来我在推特上跟的人越来越多，跟着我的人亦是日益增多，不知不觉我也迷上了该网站，天天都会上。凡是经常用推特的人一般都会用一个推特的客户端，这才能跟得上朋友们的状态更新和最火热的网络新闻。本人作为 Ubuntu 的用户，我自然就选了 Gwibber 这个基于 GNOME 的客户端来访问我的推特。这个软件功能很丰富，用起来得心应手，不过总有一个问题让我有点遗憾，就是 Gwibber 还不听从 GNOME 的代理设置。平时这也不是一个很大的问题，但是每遇中国网络封锁较严重时，都会让我暂时无法使用该软件。 解决方案&#8230; Tsocks 经过几个 Google 搜索，我最终很高兴地发现 Linux 有一个能够强迫任何软件通过 SOCKS 代理上网的工具，其名就是 tsocks。Tsocks 是一个透明 SOCKS 代理软件，只要你电脑有一个连接到国外服务器的 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>情况</strong><br />
由于最近在中国某个地方爆发了 riot, 所以境内很多网站又是无法访问 (twitter.com、facebook.com 等)，让我们这些网民很无奈。</p>
<p><strong>使用 SSH 翻墙</strong><br />
<a href="http://sprayfly.com/2009/07/05/%E5%9C%A8-linux-%E4%B8%8B%E4%BD%BF%E7%94%A8%E4%BD%A0%E7%9A%84%E7%BD%91%E7%AB%99%E4%B8%BB%E6%9C%BA%E4%BD%9C%E4%B8%BA%E5%8A%A0%E5%AF%86%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8/">我曾经介绍过</a>如何使用 SSH 来建立一个 SOCKS 代理服务器，让你能够在 Firefox 里正常访问以上所提起的网址。然而不是所有 Linux 软件都能支持代理服务器。如果你最热爱的 Linux 工具需要访问&#8221;被封&#8221;的网站，又没有嵌入的代理支持，该怎么办呢？<br />
遇到这种情况当然不要放弃该软件&#8230; 毕竟我们用的系统是 Linux 而不是以前让我们咳声叹气，丧失信心的 Windows，总有一个方法去解决问题。</p>
<p><strong>举个例子吧</strong><br />
我不久前发现了 Twitter 这个网站。我一开始不经常用，也搞不明白别人为什么对这个 web 2.0 服务都着了迷。后来我在推特上跟的人越来越多，跟着我的人亦是日益增多，不知不觉我也迷上了该网站，天天都会上。凡是经常用推特的人一般都会用一个推特的客户端，这才能跟得上朋友们的状态更新和最火热的网络新闻。本人作为 Ubuntu 的用户，我自然就选了 <a href="https://launchpad.net/gwibber">Gwibber</a> 这个基于 GNOME 的客户端来访问我的推特。这个软件功能很丰富，用起来得心应手，不过总有一个问题让我有点遗憾，就是 Gwibber <a href="https://bugs.launchpad.net/gwibber/+bug/259830">还不听从 GNOME 的代理设置</a>。平时这也不是一个很大的问题，但是每遇中国网络封锁较严重时，都会让我暂时无法使用该软件。</p>
<p><strong>解决方案&#8230; Tsocks</strong><br />
经过几个 Google 搜索，我最终很高兴地发现 Linux 有一个能够强迫任何软件通过 SOCKS 代理上网的工具，其名就是 tsocks。Tsocks 是一个透明 SOCKS 代理软件，只要你电脑有一个<a href="http://sprayfly.com/2009/07/05/%E5%9C%A8-linux-%E4%B8%8B%E4%BD%BF%E7%94%A8%E4%BD%A0%E7%9A%84%E7%BD%91%E7%AB%99%E4%B8%BB%E6%9C%BA%E4%BD%9C%E4%B8%BA%E5%8A%A0%E5%AF%86%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8/">连接到国外服务器的 SSH 隧道</a>，你就能让任何软件翻墙。</p>
<p><strong>安装并配置 Tsocks</strong><br />
以下说明都是为了那些使用 Ubuntu  的 Linux 用户，不过在别的 Linux 发行版下，安装的过程应该与此差不多。</p>
<p>在终端中:</p>
<pre>sudo apt-get install tsocks</pre>
<p>修改配置文件:</p>
<pre>sudo nano /etc/tsocks.conf</pre>
<p>将其内容改成以下几行并保存退出:</p>
<pre>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 服务使用的端口</pre>
<p>你可能需要修改一下以上内容，用你自己的 SSH 隧道设置。</p>
<p><strong>运行软件</strong><br />
用 tsocks 运行你的软件很简单，在终端中:</p>
<pre>tsocks 你的软件 &#038;</pre>
<p>我现在运行 Gwibber 都是这样运行的:</p>
<pre>tsocks gwibber &#038;</pre>
<p>祝你们翻墙愉快！</p>
<p><strong>EDIT&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;></strong></p>
<p>我今天还发现了另外一个工具，其功能似乎比 tsocks 要更丰富，配置起来更简单，而且不会那么容易出错。这个工具就是 <a href="proxychains.sourceforge.net/">proxychains</a>。以下有配置方法:</p>
<pre>sudo apt-get install proxychains</pre>
<p>修改配置文件 (/etc/proxychains.conf)，应该如下：</p>
<pre># 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
</pre>
<p>注意事项:</p>
<ol>
<li>要选 dynamic_chain 而不是 random_chain</li>
<li>可以列举几个代理服务器，proxychains  会按顺序用，代理无法访问即自动选用下一个</li>
<li>代理服务器要根据自己电脑的情况自行调整</li>
</ol>
<p><strong>运行 proxychains</strong><br />
运行 proxychains 跟运行 tsocks 完全一样。在终端中:</p>
<pre>proxychains 你的软件 &#038;</pre>
<p>比如说:</p>
<pre>proxychains chromium-browser &#038;</pre>
<p>我还是推荐你使用 proxychains！</p>
<div id="mainphotoarea"></div>]]></content:encoded>
			<wfw:commentRss>http://sprayfly.com/2009/07/09/%e7%94%a8-tsocks-%e4%bd%bf-linux-%e4%b8%8b%e6%89%80%e6%9c%89%e8%bd%af%e4%bb%b6%e8%83%bd%e5%a4%9f%e7%bf%bb%e5%a2%99/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>在 Linux 下使用你的网站主机作为加密代理服务器</title>
		<link>http://sprayfly.com/2009/07/05/%e5%9c%a8-linux-%e4%b8%8b%e4%bd%bf%e7%94%a8%e4%bd%a0%e7%9a%84%e7%bd%91%e7%ab%99%e4%b8%bb%e6%9c%ba%e4%bd%9c%e4%b8%ba%e5%8a%a0%e5%af%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8/</link>
		<comments>http://sprayfly.com/2009/07/05/%e5%9c%a8-linux-%e4%b8%8b%e4%bd%bf%e7%94%a8%e4%bd%a0%e7%9a%84%e7%bd%91%e7%ab%99%e4%b8%bb%e6%9c%ba%e4%bd%9c%e4%b8%ba%e5%8a%a0%e5%af%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 08:18:54 +0000</pubDate>
		<dc:creator>Jono</dc:creator>
				<category><![CDATA[Site News]]></category>
		<category><![CDATA[网站]]></category>
		<category><![CDATA[网络]]></category>
		<category><![CDATA[翻墙]]></category>
		<category><![CDATA[脚本]]></category>
		<category><![CDATA[gfw]]></category>
		<category><![CDATA[host]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[tunnel]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[服务器]]></category>
		<category><![CDATA[代理]]></category>

		<guid isPermaLink="false">http://sprayfly.com/?p=331</guid>
		<description><![CDATA[我曾经介绍过如何使用 Amazon EC2 建立自己的代理服务器来“翻墙“。用这个方法翻墙虽然网速很快，但还是有些缺点。Amazon EC2 是收费的，而且按小时算，所以不能随时都开着我的代理服务器。另外，每次想用代理的时候还得先等一两分钟，让服务器启动。 然而我今天看到了这个贴子，这才发现还可以使用一个普通的网站主机作为我的代理服务器。与 Amazon EC2 不同，普通的网站主机是 24/7 运行的，而且你本来就要用它做你的网站，不用额外花钱。以上帖子是专门写给使用 Dreamhost 的 Windows 用户。不过，凡是有支持 SSH 服务网站主机的 Linux 用户也可以享受翻墙的自由感。我为 Linux 用户编了一个小的 BASH 脚本，其主要功能为: 与网站主机创建一个 SSH 隧道连接 SSH 隧道用完之后，安全地关闭 SSH 隧道连接 用这个脚本，我试了一下上平时被 GFW 封杀的 youtube.com&#8230; 结果 Firefox 差点让我晕倒了! 用这个代理，网速快极了&#8230; 感觉好像我还在英国上网似的 (那边一般都用 8M 以上的宽带) &#8211; 你可以看一下视频: 介绍一下脚本的内容 export SSH_HOST=admin@yoursite.com # username@host 这个需要你自己改一下&#8230; 就是你的 webhost 给你的 SSH [...]]]></description>
			<content:encoded><![CDATA[<p>我<a href="http://sprayfly.com/2009/06/28/shell-script-for-automated-amazon-ec2-personal-proxy-server/">曾经介绍过</a>如何使用 Amazon EC2 建立自己的代理服务器来“翻墙“。用这个方法翻墙虽然网速很快，但还是有些缺点。Amazon EC2 是收费的，而且按小时算，所以不能随时都开着我的代理服务器。另外，每次想用代理的时候还得先等一两分钟，让服务器启动。</p>
<p>然而我今天看到了这个<a href="http://www.fishnote.net/?p=86">贴子</a>，这才发现还可以使用一个普通的网站主机作为我的代理服务器。与 Amazon EC2 不同，普通的网站主机是 24/7 运行的，而且你本来就要用它做你的网站，不用额外花钱。以上帖子是专门写给使用 Dreamhost 的 Windows 用户。不过，凡是有支持 SSH 服务网站主机的 Linux 用户也可以享受翻墙的自由感。我为 Linux 用户编了一个小的 BASH 脚本，其主要功能为:</p>
<ul>
<li>与网站主机创建一个 SSH 隧道连接</li>
<li>SSH 隧道用完之后，安全地关闭 SSH 隧道连接</li>
</ul>
<p>用这个脚本，我试了一下上平时被 GFW 封杀的 youtube.com&#8230; 结果 Firefox 差点让我晕倒了! 用这个代理，网速快极了&#8230; 感觉好像我还在英国上网似的 (那边一般都用 8M 以上的宽带) &#8211; 你可以看一下视频:</p>
<p><object width="400" height="250" style="display: block; margin-left: auto; margin-right: auto;"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=5468249&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=5468249&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=00ADEF&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="250"></embed></object></p>
<p><strong>介绍一下脚本的内容</strong></p>
<pre>export SSH_HOST=admin@yoursite.com # username@host</pre>
<p>这个需要你自己改一下&#8230; 就是你的 webhost 给你的 SSH 用户名和主机地址。 格式为 用户名@地址 （凡是用过 SSH 的人都应该知道写什么）</p>
<pre>if [ ! -f /tmp/.tunnel ]</pre>
<p>看看是否已经有 SSH 隧道开着。有的话就将其关闭。没有就创建新的 SSH 隧道。</p>
<pre>ssh -f -D 9999 $SSH_HOST "if [ -f ~/.tunnel ]; then rm ~/.tunnel; fi; while [ ! -f ~/.tunnel ]; do echo > /dev/null; done" &#038;</pre>
<p>创建新的 SSH 隧道，设定本地 SOCKS 端口为 9999。隧道将会开着直到远程目录 “~/” 里有人创建 .tunnel 此文件为止。</p>
<pre>touch /tmp/.tunnel</pre>
<p>在你的电脑上创建 .tunnel 这个文件。这样脚本就知道正开着一个 SSH 隧道。</p>
<pre>ssh $SSH_HOST "touch ~/.tunnel"</pre>
<p>在远程目录 “~/&#8221; 里创建 .tunnel 此文件，这将会断开你电脑与代理服务器的连接</p>
<pre>rm /tmp/.tunnel</pre>
<p>删除 .tunnel 这个文件。这样脚本就知道 SSH 隧道已关闭。</p>
<p><strong>下载并执行脚本</strong><br />
<a href="http://files.getdropbox.com/u/316115/tunnel.sh">可以在此下载脚本</a></p>
<p>下载后放在你的首目录，比如在 ~/bin/。用一个文字编辑器修改脚本里的 ssh 变量并用 chmod 改一下文件权限</p>
<pre>chmod u+x tunnel.sh</pre>
<p><strong>创建连接</strong><br />
在终端中执行脚本，执行后可以关闭终端。</p>
<p><a href="http://www.flickr.com/photos/jonolumb/3689649442/" class="tt-flickr tt-flickr-Medium" title="open_tunnel.png"><img class="alignnone" src="http://farm3.static.flickr.com/2544/3689649442_9dd0cbe710.jpg" alt="open_tunnel.png" width="500" height="335" /></a></p>
<p><strong>关闭连接</strong><br />
再次在终端中执行脚本并关闭 Firefox (如果 Firefox 还在用隧道的话，连接暂时无法关闭)</p>
<p> <a href="http://www.flickr.com/photos/jonolumb/3688843963/" class="tt-flickr tt-flickr-Medium" title="close_tunnel.png"><img class="alignnone" src="http://farm4.static.flickr.com/3640/3688843963_8fdffbed01.jpg" alt="close_tunnel.png" width="500" height="335" /></a></p>
<p><strong>用 SSH 密钥进行授权</strong><br />
你或许注意到了&#8230; 以上脚本里没有任何地方可以写下你的 SSH 密码。这就是因为我在用 SSH 密钥来进行电脑与服务器的授权工作，这样更自动化而且比将密码直接写入文本的文件里要安全多了。先打开一个终端，根据一下步骤进行密钥配置:</p>
<pre>[jonolumb@jonoxps .ssh]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jonolumb/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jonolumb/.ssh/id_rsa
Your public key has been saved in /home/jonolumb/.ssh/id_rsa.pub
The key fingerprint is:
h7:10:49:46:ab:2t:3b:a3:36:2z:15:56:d4:f2:b7:3d jonolumb@jonoxps</pre>
<p>请注意，配置时密码要留为空白。</p>
<p>将生成的 /home/jonolumb/.ssh/id_rsa.pub 的内容复制到远程服务器目录下，具体位置是:<br />
~/.ssh/authorized_keys<br />
要保证远程的 authorized_keys 和 本地的 id_rsa 文件的权限均为 700。<br />
这样就可以自动登录到远程服务器了。</p>
<p><strong>配置 Firefox 使用代理</strong><br />
创建了 SSH 隧道之后，就进入 Firefox 并打开:</p>
<pre>首选项 --> 高级 --> 连接设置</pre>
<p>选择“手动配置代理”并将其设定为:<br />
HTTP 代理: localhost 端口: 9999</p>
<p> <a href="http://www.flickr.com/photos/jonolumb/3689657500/" class="tt-flickr tt-flickr-Medium" title="firefox_proxy.png"><img class="alignnone" src="http://farm3.static.flickr.com/2536/3689657500_4c7c03d871.jpg" alt="firefox_proxy.png" width="488" height="500" /></a></p>
<p>如果你用这个脚本遇到什么问题，请跟我取得联系。我很想听你们的意见。谢谢！</p>
<div id="mainphotoarea"></div>]]></content:encoded>
			<wfw:commentRss>http://sprayfly.com/2009/07/05/%e5%9c%a8-linux-%e4%b8%8b%e4%bd%bf%e7%94%a8%e4%bd%a0%e7%9a%84%e7%bd%91%e7%ab%99%e4%b8%bb%e6%9c%ba%e4%bd%9c%e4%b8%ba%e5%8a%a0%e5%af%86%e4%bb%a3%e7%90%86%e6%9c%8d%e5%8a%a1%e5%99%a8/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
	</channel>
</rss>
