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.

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