Shadowsocks

由于众所周知的原因,只能在中华大局域网内折腾,科学上网姿势很多。

常规VPN过于笨重,自由切换线路比较费力,需要添加路由规则,Shadowsocks就是不错的选择。

本文实现简单方便的科学上网。仅供技术。

pip安装方法上篇博客写到了。

pip3 install shadowsocks
ln -s /usr/local/python3/bin/ss* /usr/local/bin
vim /etc/shadowsocks.json

单账号

{
"server":"103.30.42.88",
"server_port":443,
"password":"MyPass",
"timeout":300,
"method":"rc4-md5"
}

多账号

{
"server":"103.30.42.88",
"port_password":{
"1101":"MyPass1",
"1102":"MyPass2",
"1103":"MyPass3"
},
"timeout":300,
"method":"rc4-md5"
}

默认使用aes-256-cfb,推荐使用rc4-md5,因为 RC4比AES速度快好几倍。

各字段说明:
server:服务器IP
server_port:服务器端口
local_port:本地端端口
password:用来加密的密码
timeout:超时时间(秒)
method:加密方法,可选择 “bf-cfb”, “aes-256-cfb”, “des-cfb”, “rc4″等

启动

ssserver -c /etc/shadowsocks.json -d start

停止

ssserver -c /etc/shadowsocks.json -d stop

无配置文件命令启动

ssserver -p 443 -k MyPass -m rc4-md5 -d start

SysV服务脚本

vim /etc/init.d/shadowsocks

#!/bin/sh
# chkconfig: 2345 90 10
# description: Start or stop the Shadowsocks server
#
### BEGIN INIT INFO
# Provides: Shadowsocks
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Start or stop the Shadowsocks server
### END INIT INFO
name=shadowsocks
BIN=/usr/bin/ssserver
conf=/etc/shadowsocks.json
start(){
$BIN -c $conf -d start
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name start success"
else
echo "$name start failed"
fi
}
stop(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${BIN}" | awk '{print $2}'`
if [ ! -z $pid ]; then
$BIN -c $conf -d stop
RETVAL=$?
if [ "$RETVAL" = "0" ]; then
echo "$name stop success"
else
echo "$name stop failed"
fi
else
echo "$name is not running"
RETVAL=1
fi
}
status(){
pid=`ps -ef | grep -v grep | grep -v ps | grep -i "${BIN}" | awk '{print $2}'`
if [ -z $pid ]; then
echo "$name is not running"
RETVAL=1
else
echo "$name is running with PID $pid"
RETVAL=0
fi
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
stop
start
RETVAL=$?
;;
*)
echo "Usage: $0 { start | stop | restart | status }"
RETVAL=1
;;
esac
exit $RETVAL
chmod +x /etc/init.d/shadowsocks
service shadowsocks restart

开机自启动

chkconfig --add shadowsocks
chkconfig shadowsocks on

客户端下载
https://shadowsocks.org/en/download/clients.html