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.

447 lines
14 KiB

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