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.

376 lines
11 KiB

12 years ago
12 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
10 years ago
12 years ago
12 years ago
9 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
10 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
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
12 years ago
12 years ago
11 years ago
10 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
10 years ago
12 years ago
12 years ago
12 years ago
12 years ago
11 years ago
12 years ago
12 years ago
12 years ago
12 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 socks5
  6. proxy for embedded devices and low end boxes.
  7. It is a port of [shadowsocks](https://github.com/shadowsocks/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: 2.4.0 | [Changelog](debian/changelog)
  11. Travis CI: [![Travis CI](https://travis-ci.org/shadowsocks/shadowsocks-libev.png?branch=master)](https://travis-ci.org/shadowsocks/shadowsocks-libev) | Jenkins Matrix: [![Jenkins](https://jenkins.shadowvpn.org/buildStatus/icon?job=Shadowsocks-libev)](https://jenkins.shadowvpn.org/job/Shadowsocks-libev/)
  12. Features
  13. --------
  14. Shadowsocks-libev is writen in pure C and only depends on
  15. [libev](http://software.schmorp.de/pkg/libev.html) and
  16. [openssl](http://www.openssl.org/) or [polarssl](https://polarssl.org/).
  17. In normal usage, the memory footprint is about 600KB and the CPU utilization is
  18. no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU,
  19. 32MB memory and 4MB flash).
  20. Installation
  21. ------------
  22. #### Notes about PolarSSL
  23. * Default crypto library is OpenSSL. To build against PolarSSL,
  24. specify `--with-crypto-library=polarssl` and `--with-polarssl=/path/to/polarssl`
  25. when running `./configure`.
  26. * PolarSSL __1.2.5 or newer__ is required. Currently, PolarSSL does __NOT__ support
  27. CAST5-CFB, DES-CFB, IDEA-CFB, RC2-CFB and SEED-CFB.
  28. * RC4 is only support by PolarSSL __1.3.0 or above__.
  29. ### Debian & Ubuntu
  30. #### Install from repository
  31. Add GPG public key
  32. ```bash
  33. wget -O- http://shadowsocks.org/debian/1D27208A.gpg | sudo apt-key add -
  34. ```
  35. Add either of the following lines to your /etc/apt/sources.list
  36. ```
  37. # Debian Wheezy, Ubuntu 12.04 or any distribution with libssl > 1.0.1
  38. deb http://shadowsocks.org/debian wheezy main
  39. # Debian Squeeze, Ubuntu 11.04, or any distribution with libssl > 0.9.8, but < 1.0.0
  40. deb http://shadowsocks.org/debian squeeze main
  41. ```
  42. Then,
  43. ``` bash
  44. sudo apt-get update
  45. sudo apt-get install shadowsocks-libev
  46. ```
  47. #### Build package from source
  48. Supported Platforms:
  49. * Debian 7 (see below), 8, unstable
  50. * Ubuntu 14.10, 15.04 or higher
  51. To build packages on Debian 7 (Wheezy), you need to enable `debian-backports`
  52. to install systemd-compatibility packages like `dh-systemd` or `init-system-helpers`.
  53. This also means that you can only install those built packages on systems that have
  54. `init-system-helpers` installed.
  55. Otherwise, try to build and install directly from source. See the **Linux**
  56. section below.
  57. ``` bash
  58. cd shadowsocks-libev
  59. sudo apt-get install build-essential autoconf libtool libssl-dev \
  60. gawk debhelper dh-systemd init-system-helpers
  61. dpkg-buildpackage -us -uc -i
  62. cd ..
  63. sudo dpkg -i shadowsocks-libev*.deb
  64. ```
  65. #### Configure and start the service
  66. ```
  67. # Edit the configuration file
  68. sudo vim /etc/shadowsocks-libev/config.json
  69. # Edit the default configuration for debian
  70. sudo vim /etc/default/shadowsocks-libev
  71. # Start the service
  72. sudo /etc/init.d/shadowsocks-libev start # for sysvinit, or
  73. sudo systemctl start shasowsocks-libev # for systemd
  74. ```
  75. ### Fedora & RHEL
  76. Supported distributions include
  77. - Fedora 20, 21, rawhide
  78. - RHEL 6, 7 and derivatives (including CentOS, Scientific Linux)
  79. #### Install from repository
  80. Enable repo via `dnf`:
  81. ```
  82. su -c 'dnf copr enable librehat/shadowsocks'
  83. ```
  84. Or download yum repo on [Fedora Copr](https://copr.fedoraproject.org/coprs/librehat/shadowsocks/) and put it inside `/etc/yum.repos.d/`. The release `Epel` is for RHEL and its derivatives.
  85. Then, install `shadowsocks-libev` via `dnf`:
  86. ```bash
  87. su -c 'dnf update'
  88. su -c 'dnf install shadowsocks-libev'
  89. ```
  90. or `yum`:
  91. ```bash
  92. su -c 'yum update'
  93. su -c 'yum install shadowsocks-libev'
  94. ```
  95. ### Linux
  96. For Unix-like systems, especially Debian-based systems,
  97. e.g. Ubuntu, Debian or Linux Mint, you can build the binary like this:
  98. ```bash
  99. sudo apt-get install build-essential autoconf libtool libssl-dev
  100. ./configure && make
  101. sudo make install
  102. ```
  103. ### FreeBSD
  104. ```bash
  105. su
  106. cd /usr/ports/net/shadowsocks-libev
  107. make install
  108. ```
  109. Edit your config.json file. By default, it's located in /usr/local/etc/shadowsocks-libev
  110. To enable shadowsocks-libev, add the following rc variable to your /etc/rc.conf file.
  111. ```
  112. shadowsocks_libev_enable="YES"
  113. ```
  114. Start the shadowsocks server:
  115. ```bash
  116. service shadowsocks_libev start
  117. ```
  118. ### OpenWRT
  119. ```bash
  120. # At OpenWRT build root
  121. pushd package
  122. git clone https://github.com/shadowsocks/shadowsocks-libev.git
  123. popd
  124. # Enable shadowsocks-libev in network category
  125. make menuconfig
  126. # Optional
  127. make -j
  128. # Build the package
  129. make V=99 package/shadowsocks-libev/openwrt/compile
  130. ```
  131. ### OS X
  132. For OS X , use [homebrew](http://brew.sh) to install or build.
  133. Install homebrew
  134. ```bash
  135. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  136. ```
  137. Install shadowsocks-libev
  138. ```bash
  139. brew install shadowsocks-libev
  140. ```
  141. ### Windows
  142. For Windows, use either MinGW (msys) or Cygwin to build.
  143. At the moment, only `ss-local` is supported to build against MinGW (msys).
  144. If you are using MinGW (msys), please download OpenSSL or PolarSSL source tarball
  145. to the home directory of msys, and build it like this (may take a few minutes):
  146. * OpenSSL
  147. ```bash
  148. tar zxf openssl-1.0.1e.tar.gz
  149. cd openssl-1.0.1e
  150. ./config --prefix="$HOME/prebuilt" --openssldir="$HOME/prebuilt/openssl"
  151. make && make install
  152. ```
  153. * PolarSSL
  154. ```bash
  155. tar zxf polarssl-1.3.2-gpl.tgz
  156. cd polarssl-1.3.2
  157. make lib WINDOWS=1
  158. make install DESTDIR="$HOME/prebuilt"
  159. ```
  160. Then, build the binary using the commands below, and all `.exe` files
  161. will be built at `$HOME/ss/bin`:
  162. * OpenSSL
  163. ```bash
  164. ./configure --prefix="$HOME/ss" --with-openssl="$HOME/prebuilt"
  165. make && make install
  166. ```
  167. * PolarSSL
  168. ```bash
  169. ./configure --prefix="$HOME/ss" --with-crypto-library=polarssl --with-polarssl=$HOME/prebuilt
  170. make && make install
  171. ```
  172. Usage
  173. -----
  174. ```
  175. ss-[local|redir|server|tunnel]
  176. -s <server_host> host name or ip address of your remote server
  177. -p <server_port> port number of your remote server
  178. -l <local_port> port number of your local server
  179. -k <password> password of your remote server
  180. [-m <encrypt_method>] encrypt method: table, rc4, rc4-md5,
  181. aes-128-cfb, aes-192-cfb, aes-256-cfb,
  182. bf-cfb, camellia-128-cfb, camellia-192-cfb,
  183. camellia-256-cfb, cast5-cfb, des-cfb, idea-cfb,
  184. rc2-cfb, seed-cfb, salsa20 and chacha20
  185. [-f <pid_file>] the file path to store pid
  186. [-t <timeout>] socket timeout in seconds
  187. [-c <config_file>] the path to config file
  188. [-i <interface>] network interface to bind,
  189. not available in redir mode
  190. [-b <local_address>] local address to bind,
  191. not available in server mode
  192. [-u] enable udprelay mode,
  193. TPROXY is required in redir mode
  194. [-U] enable UDP relay and disable TCP relay,
  195. not available in local mode
  196. [-A] enable onetime authentication
  197. [-L <addr>:<port>] specify destination server address and port
  198. for local port forwarding,
  199. only available in tunnel mode
  200. [-d <addr>] setup name servers for internal DNS resolver,
  201. only available in server mode
  202. [--fast-open] enable TCP fast open,
  203. only available in local and server mode,
  204. with Linux kernel > 3.7.0
  205. [--acl <acl_file>] config file of ACL (Access Control List)
  206. only available in local and server mode
  207. [--manager-address <addr>] UNIX domain socket address
  208. only available in server and manager mode
  209. [--executable <path>] path to the executable of ss-server
  210. only available in manager mode
  211. [-v] verbose mode
  212. notes:
  213. ss-redir provides a transparent proxy function and only works on the
  214. Linux platform with iptables.
  215. ```
  216. ## Advanced usage
  217. The latest shadowsocks-libev has provided a *redir* mode. You can configure your linux based box or router to proxy all tcp traffic transparently.
  218. # Create new chain
  219. root@Wrt:~# iptables -t nat -N SHADOWSOCKS
  220. root@Wrt:~# iptables -t mangle -N SHADOWSOCKS
  221. # Ignore your shadowsocks server's addresses
  222. # It's very IMPORTANT, just be careful.
  223. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
  224. # Ignore LANs and any other addresses you'd like to bypass the proxy
  225. # See Wikipedia and RFC5735 for full list of reserved networks.
  226. # See ashi009/bestroutetb for a highly optimized CHN route list.
  227. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
  228. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
  229. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
  230. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
  231. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
  232. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
  233. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
  234. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
  235. # Anything else should be redirected to shadowsocks's local port
  236. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
  237. # Add any UDP rules
  238. root@Wrt:~# ip rule add fwmark 0x01/0x01 table 100
  239. root@Wrt:~# ip route add local 0.0.0.0/0 dev lo table 100
  240. root@Wrt:~# iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
  241. # Apply the rules
  242. root@Wrt:~# iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS
  243. root@Wrt:~# iptables -t mangle -A PREROUTING -j SHADOWSOCKS
  244. # Start the shadowsocks-redir
  245. root@Wrt:~# ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
  246. ## Security Tips
  247. Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend to
  248. set up your server's firewall rules to limit connections from each user.
  249. # Up to 32 connections are enough for normal usages
  250. iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
  251. ## License
  252. Copyright (C) 2014 Max Lv <max.c.lv@gmail.com>
  253. This program is free software: you can redistribute it and/or modify
  254. it under the terms of the GNU General Public License as published by
  255. the Free Software Foundation, either version 3 of the License, or
  256. (at your option) any later version.
  257. This program is distributed in the hope that it will be useful,
  258. but WITHOUT ANY WARRANTY; without even the implied warranty of
  259. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  260. GNU General Public License for more details.
  261. You should have received a copy of the GNU General Public License
  262. along with this program. If not, see <http://www.gnu.org/licenses/>.