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.

475 lines
14 KiB

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