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.

485 lines
15 KiB

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