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.

478 lines
15 KiB

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