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.

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