Total Pageviews

Thursday 24 December 2015

DIY代理服务器


本文介绍如何在家里设置代理服务器,并用SSH加密连接。这种方式不仅适用于在国内翻墙,也可以在公司里“遁身”:就是您不想让公司知道自己用公司的网络去了哪里。
首先,在家里找一台电脑装上 Linux操作系统(www.ubuntu.com)。如果只作为代理服务器,不需要最新最快的电脑,几年前的旧电脑就可以了。代理服务器的软件叫 squid。装上后这就自动成为代理服务器了。SSH加密服务的软件叫openssh-server;另外还需要安装火墙软件ufw。软件的安装可以在control panel里下载,或直接用指令 sudo apt-get install 。
家里的无线路由器(wireless router)分外部和内部;外部是连到运营商,用运营商给的外部地址。这个对外地址可以打开网页www.whatismyip.com查看;文中我们假设它是18.18.18.18。虽然这个地址是动态给定的,一般说来长期都不会改变。路由器的“内部”是家里的电脑、打印机、智能手机和平板电脑等,家里的IP地址一般是10.x.y.z 或者 192.168.x.y。路由器在内部和外部IP地址之间做地址转化(Network address translation)。我们把Linux服务器的IP地址必须设为手设(manual),您可以挑一个无线路由器里允许的内部任一个地址。我们在这里假设为 10.10.10.10。在家里无线路由器的DMZ(军事缓冲区)设置里,指定这个地址为外界可达地址。这个等于把外界欲联通18.18.18.18的数据包直接送到10.10.10.10,就是我们的服务器。为了防止黑客袭击服务器,设置防火墙只接受SSH:
sudo ufw enable
sudo ufw allow 22
sudo ufw default deny
这样,家里的SSH和 proxy server 的设置就完全了。现在谈谈怎么在手提或座机电脑上通过家里的服务器访问网站。我们假设这是个微软系统;其他系统类似。
微软上一款常用的SSH软件叫puTTY(www.putty.org)。puTTY 不仅能接通远程的SSH,还能在SSH中开设通道(tunnels):我们将开通网络代理服务的通道。具体设置是如下:连接方式选择SSH; 对方IP地址选家里的外部地址(我们这里是18.18.18.18)。在左边菜单,选择connection, SSH, Tunnels; 右边“add new forwarded port”,source port 选择3128,destination 选择 localhost:3128 (3128是proxy service的default端口)。然后按“Add”。把这个设置存下,下次直接调出就可以了。执行puTTY后,就会开始SSH连接,敲入您家里Linux服务器的用户密码。
SSH连接成功后,您就可以用家里的网络代理服务了。注意,proxy server 现在是 localhost,就是SSH的这一端。比如用google chrome, short-cut properties 的目标应为:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --proxy-server=localhost:3128
好了, 关闭已有的chrome,新打开的chrome就可以访问中国黑名单上的任何网站了.

Q:有一问题想请教:我有个Dell server在家里,the first NIC is connecting to a static IP, acting as a web server (windows 2003). I wanted to use the 2nd NIC to fit into a switch (or a route) to forward the internet access, how should I configure the 2nd NIC (IP/Subnet/Gateway/DNS)?或请推荐一些资料.
A:You have to tell me how the connections are done. Do you use NIC1 to connect to cable/DSL modem, and NIC2 to your wireless router? If that’s the case, you need to configure the 2003 server as a NAT router (http://support.microsoft.com/kb/816581). 
Typically wireless router is connected to the modem, and your server is behind it. If you want your server to be reachable from outside, do the DMZ setup as described in the article. By doing that you open up the server to all services for outsiders, so you need to configure firewalls carefully. In this setup you don’t really need the second NIC; all other machines in your house go to the wireless router directly.

Q:I am stuck with the step of 我们把Linux服务器的IP地址必须设为手设 (manual). Would you please elaborate on this step? Is it the same as static IP address assignment in the interfaces file? Please advise.
A:Yes I meant static address. You can either modify the interface file, or use GUI as described in the webpage
http://askubuntu.com/questions/338442/how-to-set-static-ip-address