Total Pageviews

Monday 9 July 2012

利用shadowsocks-nodejs翻墙

前提:你需要一台linux vps.

首先在本地windows安装nodejs环境,下载地址-http://nodejs.org/dist/v0.8.1/node-v0.8.1-x86.msi

用putty登录vps,输入如下命令:
git clone git://github.com/joyent/node
cd node
./configure
make
make install

或者:
wget http://nodejs.org/dist/v0.8.2/node-v0.8.2.tar.gz
tar zxvf  node-v0.8.2.tar.gz
cd  node-v0.8.2
./configure
make
make install
这样,vps上的node环境也搭建好了。

在linux vps上,克隆源码:
git clone --branch coffee https://github.com/shadowsocks/shadowsocks-nodejs
cd shadowsocks-nodejs
修改里面的config.json文件如下:
{
    "server":"your-vps-ip",
    "server_port":8389, (因为我已在vps上装了shadowsocks,它占用了8388,所以此处改为8389)
    "local_port":1083, (因为我已在vps上装了shadowsocks,它对应的客户端机器的端口是1080,所以此处需要修改为其他值,我改为了1083)
    "password":"your-password",
    "timeout":60
}


运行服务器端程序:
node server.js > /dev/null & (这样node就会在后台运行;即使你关闭了putty,node依然会在你的vps里运行。注意:这里不要用setsid node server.js,这种setsid命令不太可靠,在你关闭putty后,相关的服务比如node很容易退出,并未在后台运行。)

回到本地windows机器,下载源码: https://github.com/shadowsocks/shadowsocks-nodejs/archive/coffee.zip,解压,进入解压出来的目录,
修改里面的config.json文件如下:
{
    "server":"your-vps-ip",
    "server_port":8389, (因为我已在vps上装了shadowsocks,它占用了8388,所以此处改为8389)
    "local_port":1083, (因为我已在vps上装了shadowsocks,它对应的客户端机器的端口是1080,所以此处需要修改为其他值,我改为了1083)
    "password":"your-password",
    "timeout":60
}

复制config.json到用户目录(我的是c:\users\my-username),然后在开始 -> 运行 -> cmd里面输入命令node i:\shadowsocks-nodejs\local.js(这里i:\shadowsocks-nodejs为我的解压目录路径,请改为你的解压目录路径),回车,如果显示:
calculating ciphers
server listening at port 1083
然后设置浏览器的socks5 代理为127.0.0.1:1083,即可翻墙.

项目地址:
https://github.com/shadowsocks/shadowsocks-nodejs/tree/coffee

ps:  shadowsocks-nodejs最好搭配浏览器k-meleon使用。我用shadowsocks-nodejs搭配ff,竟然打不开blogger.com,而搭配k-meleon则没有问题。

注:shadowsocks-nodejs服务比较容易自行退出,可考虑用cron命令来使它自动重启:
*/1 * * * * killall node; cd /root/shadowsocks-nodejs/; /usr/local/bin/node server.js > log &

或者把cd /root/shadowsocks-nodejs; /usr/local/bin/node server.js > log &加到/etc/rc.local里面也可,这样如果shadowsocks-nodejs服务退出了,重启vps,它就又运行了。

此法用来看youtube,非常流畅.
----------------------------

shadowsocks-nodejs的master版的用法如下:

首先登陆你的linux vps,然后
git clone https://github.com/clowwindy/shadowsocks-nodejs
cd shadowsocks-nodejs
root@AR:~/shadowsocks-nodejs# ls
bin   CHANGES      CONTRIBUTING.md LICENSE       README.md  test
Cakefile  config.json  lib package.json  src
root@AR:~/shadowsocks-nodejs# nano config.json
root@AR:~/shadowsocks-nodejs# cat config.json
{
    "server":"your_vps_ip",
    "server_port":8388,
    "local_port":1083,
    "password":"你所设置的密码",
    "timeout":600,
    "method":"aes-256-cfb"
}
root@AR:~/shadowsocks-nodejs# cd bin
root@AR:~/shadowsocks-nodejs/bin# ls
sslocal  ssserver


root@AR:~/shadowsocks-nodejs/bin# nohup ./ssserver > /dev/null &
服务器端设置完毕。

客户端机器是linux desktop os的情形:
登录vps,输入如下命令:
# git clone git://github.com/joyent/node
# cd node
# ./configure
# make
# make install
这样, 本地linux机器上的node环境就搭建好了。
(如果是mac桌面系统,则运行brew install node来安装node环境。)

然后,
git clone https://github.com/clowwindy/shadowsocks-nodejs
cd shadowsocks-nodejs
~/shadowsocks-nodejs# ls
bin   CHANGES      CONTRIBUTING.md LICENSE       README.md  test
Cakefile  config.json  lib package.json  src


~/shadowsocks-nodejs# nano config.json
~/shadowsocks-nodejs# cat config.json
{
    "server":"your_vps_ip",
    "server_port":8388,
    "local_port":1083,
    "password":"你所设置的密码",
    "timeout":600,
    "method":"aes-256-cfb"
}
~/shadowsocks-nodejs# cd bin
~/shadowsocks-nodejs/bin# ls
sslocal  ssserver


~/shadowsocks-nodejs/bin# nohup ./sslocal > /dev/null &
客户端设置完毕。

然后设置firefox浏览器/safari浏览器的socks5代理为127.0.0.1:1083,即可翻墙。
------------------

利用shadowsocks-nodejs的local-socks5版本翻墙 (不建议使用此法,太耗内存了)

root@localhost:~# git clone --branch local-socks5 https://github.com/shadowsocks/shadowsocks-nodejs shadowsocks-nodejs_local-socks5-branch
root@localhost:~# cd shadowsocks-nodejs_local-socks5-branch
root@localhost:~/shadowsocks-nodejs_local-socks5-branch# ls
encrypt.js  local.js  merge_sort.js  README.md    server.js  test_encryption.js
root@localhost:~/shadowsocks-nodejs_local-socks5-branch# nano server.js

(把里面的PORT的值设为8488
 把KEY的值设为my_key)
root@localhost:~/shadowsocks-nodejs_local-socks5-branch# node server.js > /dev/null &

回到本地机器,我的是mac.
先连上某个vpn,因为shadowsocks是敏感词,直接clone会失败。
yudeMacBook-Air:~ brite$ git clone --branch local-socks5 https://github.com/shadowsocks/shadowsocks-nodejs shadowsocks-nodejs_local-socks5-branch 
yudeMacBook-Air:~ brite$ cd shadowsocks-nodejs_local-socks5-branch
yudeMacBook-Air:shadowsocks-nodejs_local-socks5-branch brite$ ls
README.md        local.js        server.js
encrypt.js        merge_sort.js        test_encryption.js
yudeMacBook-Air:shadowsocks-nodejs_local-socks5-branch brite$ nano local.js

(...
var SERVER = 'my-vps-ip';
var REMOTE_PORT = 8488;
var PORT = 1084;
var KEY = 'my_key';

...)
yudeMacBook-Air:shadowsocks-nodejs_local-socks5-branch brite$ node local.js

会显示:
calculating ciphers
server listening at port 1084


然后设置firefox浏览器/safari浏览器的socks5代理为127.0.0.1:1084,即可翻墙。

项目地址:https://github.com/shadowsocks/shadowsocks-nodejs/tree/local-socks5 
----------------------------------------------------------

git clone --branch local-http https://github.com/shadowsocks/shadowsocks-nodejs shadowsocks-nodejs-local-http-branch

项目地址:https://github.com/shadowsocks/shadowsocks-nodejs/tree/local_http
--------------------------------

shadowsocks-nodejs

NPM version Build Status
shadowsocks-nodejs is a node.js port of shadowsocks.

Usage

Download the lastest Node stable release. Don't just use master branch of Node source code from Github! It's not stable.
Run
npm install -g shadowsocks
Create a file named config.json, with the following content.
{
    "server":"my_server_ip",
    "server_port":8388,
    "local_port":1080,
    "password":"barfoo!",
    "timeout":600,
    "method":"table",
    "local_address":"127.0.0.1"
}
Explaination of the fields:
server          your server IP (IPv4/IPv6), notice that your server will listen to this IP
server_port     server port
local_port      local port
password        a password used to encrypt transfer
timeout         in seconds
method          encryption method, "bf-cfb", "aes-256-cfb", "des-cfb", "rc4", etc. Default is table
local_address   local binding address, leave it alone if you don't know what it means
cd into the directory of config.json. Run ssserver on your server. Use Supervisor.
On your client machine, run sslocal.
Change the proxy setting in your browser into
protocol: socks5
hostname: 127.0.0.1
port:     your local_port

Advanced

You can use args to override settings from config.json.(注:这句话不成立。我使用args的方法,没法指定本地机器所要监听的端口号。所以在客户端填入参数后,不能成功翻墙。所以还是建议搭配配置文件使用。)
sslocal -s server_name -p server_port -l local_port -k password -m bf-cfb -b local_address
ssserver -p server_port -k password -m bf-cfb -t timeout
ssserver -c /etc/shadowsocks/config.json
Example of multi-user server support can be found in test/config-multi-passwd.json.

Developing

You can build coffee source code and test it:
npm install -g coffee-script
cake build test
from https://github.com/ysmood/shadowsocks-nodejs