Total Pageviews

Monday, 13 June 2016

利用shadowsocks的rust版shadowsocks-rust翻墙

首先linux vps上搭建rust环境:
curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
(必须是nightly版。不要安装stable版,即不要运行:
curl -sf -L https://static.rust-lang.org/rustup.sh | sh
否则下面安装shadowsocks-rust会遇到错误)
运行命令后,显示:
...
install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh

install: installing component 'rustc'

install: installing component 'rust-docs'

install: installing component 'cargo'

    Rust is ready to roll.

则表明安装成功,生成了可执行文件cargo.
参见http://briteming.blogspot.com/2015/11/rust.html

然后,
git clone https://github.com/zonyitoo/shadowsocks-rust
cd shadowsocks-rust

root@AR:~/shadowsocks-rust# ls
appveyor.yml  Cargo.toml  LICENSE    src
Cargo.lock    examples   README.md
root@AR:~/shadowsocks-rust# cargo build --release
会显示:
...
Compiling coio v0.2.0 (https://github.com/zonyitoo/coio-rs.git#d1714e13)
   Compiling shadowsocks-rust v0.9.14 (file:///root/shadowsocks-rust)
src/crypto/table.rs:28:5: 28:27 warning: unused import, #[warn(unused_imports)] on by default
src/crypto/table.rs:28 use crypto::digest::Digest;
                           ^~~~~~~~~~~~~~~~~~~~~~
root@AR:~/shadowsocks-rust# ls
appveyor.yml  Cargo.toml  LICENSE    src
Cargo.lock    examples   README.md  target
(生成了target目录)
root@AR:~/shadowsocks-rust# cd target
root@AR:~/shadowsocks-rust/target# ls
release
root@AR:~/shadowsocks-rust/target# cd release
root@AR:~/shadowsocks-rust/target/release# ls
build  examples      native  sslocal   ssurl
deps   libshadowsocks.rlib  socks5-tool  ssserver
root@AR:~/shadowsocks-rust/target/release# nano config.json
root@AR:~/shadowsocks-rust/target/release# cat config.json
{
  "server": "0.0.0.0",
  "server_port": 8188,
  "local_address": "127.0.0.1", 
  "local_port": 1080,
  "password": "mypassword",
  "timeout": 600,
  "method": "aes-256-cfb"
}
(这里的 "local_address": "127.0.0.1",可以不写出来。但是在客户机器上,则一定要写出来。
root@AR:~/shadowsocks-rust/target/release# nohup ./ssserver -c config.json > /dev/null &
这样,服务器端就搭建好了。

在客户机器上。如果你的是windows机器,那么在shadowsocks的windows客户端里,填入相关参数即可。如果你的是mac,那么在shadowsocks的mac客户端-shadowsocksX里,填入相关参数即可.当然你也可在mac的终端里安装rust和运行有关的命令来启动shadowsocks-rust。操作如下:
brew install curl
curl -sSf https://static.rust-lang.org/rustup.sh | sh -s -- --channel=nightly
运行命令后,显示:
...

install: creating uninstall script at /usr/local/lib/rustlib/uninstall.sh

install: installing component 'rustc'

install: installing component 'rust-docs'

install: installing component 'cargo'

    Rust is ready to roll.

则表明安装成功。

然后,
git clone https://github.com/zonyitoo/shadowsocks-rust
cd shadowsocks-rust
cargo build --release
会显示:
...
Compiling coio v0.2.0 (https://github.com/zonyitoo/coio-rs.git#d1714e13)
   Compiling shadowsocks-rust v0.9.14 (file:///root/shadowsocks-rust)
src/crypto/table.rs:28:5: 28:27 warning: unused import, #[warn(unused_imports)] on by default
src/crypto/table.rs:28 use crypto::digest::Digest;
这表明shadowsocks-rust编译成功。

yudeMacBook-Air:shadowsocks-rust brite$ ls
Cargo.lock LICENSE  appveyor.yml src
Cargo.toml README.md examples target
yudeMacBook-Air:shadowsocks-rust brite$ cd target
yudeMacBook-Air:target brite$ ls
release
yudeMacBook-Air:target brite$ cd release
yudeMacBook-Air:release brite$ ls
build   libshadowsocks.rlib ssserver
config.json  native   ssurl
deps   socks5-tool
examples  sslocal
yudeMacBook-Air:release brite$ nano config.json
(config.json的内容如下:
{
"server": "my_server_ip",
"server_port": 8188,
"local_address": "127.0.0.1", 
"local_port": 1080,
"password": "mypassword",
"timeout": 600,
"method": "aes-256-cfb"
}    )
yudeMacBook-Air:release brite$ nohup ./sslocal -c config.json > /dev/null &
这样shadowsocks-rust的客户端就搭建好了。
然后设置浏览器的socks5代理为127.0.0.1:1080,即可翻墙。

项目地址:https://github.com/zonyitoo/shadowsocks-rust