You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

422 lines
11 KiB

12 years ago
12 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
11 years ago
12 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. shadowsocks-libev
  2. =================
  3. Intro
  4. -----
  5. [Shadowsocks-libev](http://shadowsocks.org) is a lightweight secured scoks5
  6. proxy for embedded devices and low end boxes.
  7. It is a port of [shadowsocks](https://github.com/clowwindy/shadowsocks)
  8. created by [@clowwindy](https://github.com/clowwindy) maintained by
  9. [@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang).
  10. Current version: 1.4.2 | [![Build Status](https://travis-ci.org/madeye/shadowsocks-libev.png?branch=master)](https://travis-ci.org/madeye/shadowsocks-libev)
  11. Changelog
  12. ---------
  13. 1.4.2 -- Sun, 05 Jan 2014 10:05:29 +0900
  14. * Fix the UDP relay issues.
  15. * Add syslog support.
  16. 1.4.1 -- Tue, 12 Nov 2013 03:57:21 +0000
  17. * Add multi-port support.
  18. * Add PolarSSL support by @linusyang.
  19. 1.4.0 -- Sun, 08 Sep 2013 02:20:40 +0000
  20. * Add standard socks5 udp support.
  21. 1.3.3 -- Fri, 21 Jun 2013 09:59:20 +0800
  22. * Provide more info in verbose mode.
  23. 1.3.2 -- Sun, 09 Jun 2013 09:52:31 +0000
  24. * Fix some ciphers by @linusyang.
  25. 1.3.1 -- Tue, 04 Jun 2013 00:56:17 +0000
  26. * Support more cihpers: camellia, idea, rc2 and seed.
  27. 1.3 -- Thu, 16 May 2013 10:51:15 +0800
  28. * Able to bind connections to specific interface
  29. * Support more ciphers: aes-128-cfb, aes-192-cfb, aes-256-cfb, bf-cfb, cast5-cfb, des-cfb
  30. 1.2 -- Tue, 07 May 2013 14:10:33 +0800
  31. * Close timeouted TCP connections
  32. * Fix a high load issue
  33. 1.1 -- Wed, 10 Apr 2013 12:11:36 +0800
  34. * Fix a IPV6 resolve issue
  35. 1.0 -- Sat, 06 Apr 2013 16:59:15 +0800
  36. * Initial release
  37. Features
  38. --------
  39. Shadowsocks-libev is writen in pure C and only depends on
  40. [libev](http://software.schmorp.de/pkg/libev.html) and
  41. [openssl](http://www.openssl.org/) or [polarssl](https://polarssl.org/).
  42. In normal usage, the memory consumption is about 600KB and the CPU utilization is
  43. no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU,
  44. 32MB memory and 4MB flash).
  45. Installation
  46. ------------
  47. #### Notes about PolarSSL
  48. * Default crypto library is OpenSSL. To build against PolarSSL,
  49. specify `--with-crypto-library=polarssl` and `--with-polarssl=/path/to/polarssl`
  50. when running `./configure`.
  51. * PolarSSL __1.2.5 or newer__ is required. Currently, PolarSSL does __NOT__ support
  52. CAST5-CFB, DES-CFB, IDEA-CFB, RC2-CFB and SEED-CFB.
  53. * RC4 is only support by PolarSSL __1.3.0 or above__.
  54. ### Debian & Ubuntu
  55. Add either of the following lines to your /etc/apt/sources.list
  56. ```
  57. # Debian Wheezy, Ubuntu 12.04 or any distribution with libssl > 1.0.1
  58. deb http://shadowsocks.org/debian wheezy main
  59. # Debian Squeeze, Ubuntu 11.04, or any distribution with libssl > 0.9.8, but < 1.0.0
  60. deb http://shadowsocks.org/debian squeeze main
  61. ```
  62. Then,
  63. ``` bash
  64. sudo apt-get update
  65. sudo apt-get install shadowsocks
  66. # Edit the configuration
  67. sudo vim /etc/shadowsocks/config.json
  68. # Start the service
  69. sudo /etc/init.d/shadowsocks start
  70. ```
  71. ### CentOS
  72. Install the compile tools
  73. ```bash
  74. yum install -y gcc automake autoconf libtool make build-essential autoconf libtool gcc
  75. yum install -y curl curl-devel zlib-devel openssl-devel perl perl-devel cpio expat-devel gettext-devel
  76. ```
  77. Compile and install
  78. ```bash
  79. ./configure && make
  80. make install
  81. ```
  82. Create config.json
  83. ```bash
  84. mkdir /etc/shadowsocks
  85. vi /etc/shadowsocks/config.json
  86. ```
  87. Then fill your infomation
  88. Create the service file
  89. ```bash
  90. vi /etc/rc.d/init.d/shadowsocks
  91. ```
  92. Paste below code in vi
  93. ```bash
  94. #!/bin/sh
  95. ### BEGIN INIT INFO
  96. # Provides: shadowsocks
  97. # Required-Start: $network $local_fs $remote_fs
  98. # Required-Stop: $remote_fs
  99. # Default-Start: 2 3 4 5
  100. # Default-Stop: 0 1 6
  101. # Short-Description: lightweight secured scoks5 proxy
  102. # Description: Shadowsocks-libev is a lightweight secured
  103. # scoks5 proxy for embedded devices and low end boxes.
  104. #
  105. ### END INIT INFO
  106. # Author: Vinna
  107. # Source function library.
  108. . /etc/rc.d/init.d/functions
  109. # Source networking configuration.
  110. . /etc/sysconfig/network
  111. NAME=shadowsocks
  112. DAEMON=/usr/local/bin/ss-server
  113. prog=$(basename $DAEMON)
  114. PIDFILE=/var/run/$NAME/$prog.pid
  115. CONFFILE=/etc/$NAME/config.json
  116. lockfile=/var/lock/subsys/$NAME/$prog
  117. start()
  118. {
  119. echo -n $"Starting $prog: "
  120. daemon $DAEMON -c $CONFFILE -f $PIDFILE
  121. retval=$?
  122. echo
  123. [ $retval -eq 0 ] && touch $lockfile
  124. return $retval
  125. }
  126. stop()
  127. {
  128. echo -n $"Stopping $prog: "
  129. killproc -p $PIDFILE $DAEMON
  130. RETVAL=$?
  131. [ $RETVAL -eq 0 ] && rm -f $lockfile
  132. echo
  133. return $retval
  134. }
  135. restart() {
  136. stop
  137. start
  138. }
  139. rh_status() {
  140. status $prog
  141. }
  142. rh_status_q() {
  143. rh_status >/dev/null 2>&1
  144. }
  145. case "$1" in
  146. start)
  147. rh_status_q && exit 0
  148. $1
  149. ;;
  150. stop)
  151. rh_status_q || exit 0
  152. $1
  153. ;;
  154. restart)
  155. $1
  156. ;;
  157. status)
  158. rh_status
  159. ;;
  160. condrestart|try-restart)
  161. rh_status_q || exit 0
  162. ;;
  163. *)
  164. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart}"
  165. exit 2
  166. esac
  167. ```
  168. Then save and quit vi
  169. Ctreate some folder
  170. ```bash
  171. mkdir /var/run/shadowsocks
  172. mkdir /var/lock/subsys/shadowsocks
  173. ```
  174. Then start it
  175. ```bash
  176. service shadowsocks start
  177. ```
  178. ### Linux
  179. For Unix-like systems, especially Debian-based systems,
  180. e.g. Ubuntu, Debian or Linux Mint, you can build the binary like this:
  181. ```bash
  182. sudo apt-get install build-essential autoconf libtool libssl-dev
  183. ./configure && make
  184. sudo make install
  185. ```
  186. ### FreeBSD
  187. ```bash
  188. su
  189. cd /usr/ports/net/shadowsocks-libev
  190. make install
  191. ```
  192. Edit your config.json file. By default, it's located in /usr/local/etc/shadowsocks-libev
  193. To enable shadowsocks-libev, add the following rc variable to your /etc/rc.conf file.
  194. ```
  195. shadowsocks_libev_enable="YES"
  196. ```
  197. Start the shadowsocks server:
  198. ```bash
  199. service shadowsocks_libev start
  200. ```
  201. ### OpenWRT
  202. ```bash
  203. # At OpenWRT build root
  204. pushd package
  205. git clone https://github.com/madeye/shadowsocks-libev.git
  206. popd
  207. # Enable shadowsocks-libev in network category
  208. make menuconfig
  209. # Optional
  210. make -j
  211. # Build the package
  212. make V=99 package/shadowsocks-libev/openwrt/compile
  213. ```
  214. ### Windows
  215. For Windows, use either MinGW (msys) or Cygwin to build.
  216. At the moment, only `ss-local` is supported to build against MinGW (msys).
  217. If you are using MinGW (msys), please download OpenSSL or PolarSSL source tarball
  218. to the home directory of msys, and build it like this (may take a few minutes):
  219. * OpenSSL
  220. ```bash
  221. tar zxf openssl-1.0.1e.tar.gz
  222. cd openssl-1.0.1e
  223. ./config --prefix="$HOME/prebuilt" --openssldir="$HOME/prebuilt/openssl"
  224. make && make install
  225. ```
  226. * PolarSSL
  227. ```bash
  228. tar zxf polarssl-1.3.2-gpl.tgz
  229. cd polarssl-1.3.2
  230. make lib WINDOWS=1
  231. make install DESTDIR="$HOME/prebuilt"
  232. ```
  233. Then, build the binary using the commands below, and all `.exe` files
  234. will be built at `$HOME/ss/bin`:
  235. * OpenSSL
  236. ```bash
  237. ./configure --prefix="$HOME/ss" --with-openssl="$HOME/prebuilt"
  238. make && make install
  239. ```
  240. * PolarSSL
  241. ```bash
  242. ./configure --prefix="$HOME/ss" --with-crypto-library=polarssl --with-polarssl=$HOME/prebuilt
  243. make && make install
  244. ```
  245. Usage
  246. -----
  247. ```
  248. usage:
  249. ss-[local|redir|server]
  250. -s <server_host> host name or ip address of your remote server
  251. -p <server_port> port number of your remote server
  252. -l <local_port> port number of your local server
  253. -k <password> password of your remote server
  254. [-m <encrypt_method>] encrypt method, supporting table, rc4,
  255. aes-128-cfb, aes-192-cfb, aes-256-cfb,
  256. bf-cfb, camellia-128-cfb, camellia-192-cfb,
  257. camellia-256-cfb, cast5-cfb, des-cfb,
  258. idea-cfb, rc2-cfb and seed-cfb
  259. [-f <pid_file>] valid path to the pid file
  260. [-t <timeout>] socket timeout in seconds
  261. [-c <config_file>] json format config file
  262. [-i <interface>] specific network interface to bind,
  263. only available in local and server modes
  264. [-b <local_address>] specific local address to bind,
  265. only available in local and redir modes
  266. [-u] udprelay mode to supprot udp traffic
  267. only available in local and server modes
  268. [-v] verbose mode, debug output in console
  269. notes:
  270. ss-redir provides a transparent proxy function and only works on the
  271. Linux platform with iptables.
  272. ```
  273. ## Advanced usage
  274. The latest shadowsocks-libev has provided a *redir* mode. You can configure your linux based box or router to proxy all tcp traffic transparently.
  275. # Create new chain
  276. root@Wrt:~# iptables -t nat -N SHADOWSOCKS
  277. # Ignore your shadowsocks server's addresses
  278. # It's very IMPORTANT, just be careful.
  279. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
  280. # Ignore LANs and any other addresses you'd like to bypass the proxy
  281. # See Wikipedia and RFC5735 for full list of reserved networks.
  282. # See ashi009/bestroutetb for a highly optimized CHN route list.
  283. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
  284. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
  285. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
  286. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
  287. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
  288. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
  289. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
  290. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
  291. # Anything else should be redirected to shadowsocks's local port
  292. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
  293. # Apply the rules
  294. root@Wrt:~# iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS
  295. # Start the shadowsocks-redir
  296. root@Wrt:~# ss-redir -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
  297. ## Security Tips
  298. Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend to
  299. set up your server's firewall rules to limit connections from each user.
  300. # Up to 32 connections are enough for normal usages
  301. iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
  302. ## License
  303. Copyright (C) 2013 Max Lv <max.c.lv@gmail.com>
  304. This program is free software: you can redistribute it and/or modify
  305. it under the terms of the GNU General Public License as published by
  306. the Free Software Foundation, either version 3 of the License, or
  307. (at your option) any later version.
  308. This program is distributed in the hope that it will be useful,
  309. but WITHOUT ANY WARRANTY; without even the implied warranty of
  310. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  311. GNU General Public License for more details.
  312. You should have received a copy of the GNU General Public License
  313. along with this program. If not, see <http://www.gnu.org/licenses/>.