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.

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