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.

435 lines
14 KiB

9 years ago
12 years ago
9 years ago
11 years ago
11 years ago
11 years ago
7 years ago
9 years ago
8 years ago
12 years ago
9 years ago
12 years ago
11 years ago
11 years ago
11 years ago
7 years ago
12 years ago
7 years ago
7 years ago
7 years ago
9 years ago
7 years ago
8 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
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
7 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
7 years ago
11 years ago
7 years ago
  1. # shadowsocks-libev
  2. ## Intro
  3. [Shadowsocks-libev](https://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), and maintained by
  7. [@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang).
  8. Current version: 3.0.0 | [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 depends on
  12. [libev](http://software.schmorp.de/pkg/libev.html).
  13. In normal usage, the memory footprint is about 600KB and the CPU utilization is
  14. no more than 5% on a low-end router (Buffalo WHR-G300N V2 with a 400MHz MIPS CPU,
  15. 32MB memory and 4MB flash).
  16. For a full list of feature comparison between different versions of shadowsocks,
  17. refer to the [Wiki page](https://github.com/shadowsocks/shadowsocks/wiki/Feature-Comparison-across-Different-Versions).
  18. ## Prerequisites
  19. ### Get the latest source code
  20. To get the latest source code, you should also update the submodules as following:
  21. ```bash
  22. git clone https://github.com/shadowsocks/shadowsocks-libev.git
  23. cd shadowsocks-libev
  24. git submodule update --init --recursive
  25. ```
  26. ### Build and install the latest mbedTLS and libsodium
  27. ```bash
  28. export LIBSODIUM_VER=1.0.11
  29. export MBEDTLS_VER=2.4.0
  30. wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
  31. tar xvf libsodium-$LIBSODIUM_VER.tar.gz
  32. pushd libsodium-$LIBSODIUM_VER
  33. ./configure --prefix=/usr && make
  34. sudo make install
  35. popd
  36. wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
  37. tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
  38. pushd mbedtls-$MBEDTLS_VER
  39. make SHARED=1 CFLAGS=-fPIC
  40. sudo make install
  41. popd
  42. ```
  43. ## Installation
  44. ### Distribution-specific guide
  45. - [Debian & Ubuntu](#debian--ubuntu)
  46. + [Install from repository](#install-from-repository)
  47. + [Build deb package from source](#build-deb-package-from-source)
  48. + [Configure and start the service](#configure-and-start-the-service)
  49. - [Fedora & RHEL](#fedora--rhel)
  50. + [Build from source with centos](#build-from-source-with-centos)
  51. + [Install from repository](#install-from-repository-1)
  52. - [Archlinux](#archlinux)
  53. - [NixOS](#nixos)
  54. - [Nix](#nix)
  55. - [Directly build and install on UNIX-like system](#linux)
  56. - [FreeBSD](#freebsd)
  57. - [OpenWRT](#openwrt)
  58. - [OS X](#os-x)
  59. - [Windows](#windows)
  60. * * *
  61. ### Pre-build configure guide
  62. For a complete list of avaliable configure-time option,
  63. try `configure --help`.
  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. Shadowsocks-libev is available in the official repository for Debian 9("Stretch"), unstable, Ubuntu 16.10 and later derivatives:
  68. ```bash
  69. sudo apt update
  70. sudo apt install shadowsocks-libev
  71. ```
  72. For Debian Jessie users, please install it from `jessie-backports`:
  73. ```bash
  74. sudo sh -c 'printf "deb http://httpredir.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list'
  75. sudo apt update
  76. sudo apt -t jessie-backports install shadowsocks-libev
  77. ```
  78. #### Build deb package from source
  79. Supported Platforms:
  80. * Debian 7 (see below), 8, 9, unstable
  81. * Ubuntu 14.04 (see below), Ubuntu 14.10, 15.04, 15.10 or higher
  82. **Note for Ubuntu 14.04 users**:
  83. Packages built on Ubuntu 14.04 may be used in later Ubuntu versions. However,
  84. packages built on Debian 7/8/9 or Ubuntu 14.10+ **cannot** be installed on
  85. Ubuntu 14.04.
  86. **Note for Debian 7.x users**:
  87. To build packages on Debian 7 (Wheezy), you need to enable `debian-backports`
  88. to install systemd-compatibility packages like `dh-systemd` or `init-system-helpers`.
  89. Please follow the instructions on [Debian Backports](https://backports.debian.org).
  90. This also means that you can only install those built packages on systems that have
  91. `init-system-helpers` installed.
  92. Otherwise, try to build and install directly from source. See the [Linux](#linux)
  93. section below.
  94. ``` bash
  95. cd shadowsocks-libev
  96. sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool \
  97. gawk debhelper dh-systemd init-system-helpers pkg-config asciidoc xmlto apg libpcre3-dev \
  98. libev-dev libudns-dev dh-autoreconf
  99. ./autogen.sh && dpkg-buildpackage -b -us -uc -i
  100. cd ..
  101. sudo dpkg -i shadowsocks-libev*.deb
  102. ```
  103. #### Configure and start the service
  104. ```
  105. # Edit the configuration file
  106. sudo vim /etc/shadowsocks-libev/config.json
  107. # Edit the default configuration for debian
  108. sudo vim /etc/default/shadowsocks-libev
  109. # Start the service
  110. sudo /etc/init.d/shadowsocks-libev start # for sysvinit, or
  111. sudo systemctl start shadowsocks-libev # for systemd
  112. ```
  113. ### Fedora & RHEL
  114. Supported distributions include
  115. - Fedora 22, 23, 24
  116. - RHEL 6, 7 and derivatives (including CentOS, Scientific Linux)
  117. #### Build from source with centos
  118. If you are using CentOS 7, you need to install these prequirement to build from source code
  119. ```bash
  120. yum install epel-release -y
  121. yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel -y
  122. ```
  123. #### Install from repository
  124. Enable repo via `dnf`:
  125. ```
  126. su -c 'dnf copr enable librehat/shadowsocks'
  127. ```
  128. 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.
  129. Then, install `shadowsocks-libev` via `dnf`:
  130. ```bash
  131. su -c 'dnf update'
  132. su -c 'dnf install shadowsocks-libev'
  133. ```
  134. or `yum`:
  135. ```bash
  136. su -c 'yum update'
  137. su -c 'yum install shadowsocks-libev'
  138. ```
  139. ### Archlinux
  140. ```bash
  141. sudo pacman -S shadowsocks-libev
  142. ```
  143. Please refer to downstream [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/trunk?h=packages/shadowsocks-libev)
  144. script for extra modifications and distribution-specific bugs.
  145. ### NixOS
  146. ```bash
  147. nix-env -iA nixos.shadowsocks-libev
  148. ```
  149. ### Nix
  150. ```bash
  151. nix-env -iA nixpkgs.shadowsocks-libev
  152. ```
  153. ### Linux
  154. For Unix-like systems, especially Debian-based systems,
  155. e.g. Ubuntu, Debian or Linux Mint, you can build the binary like this:
  156. ```bash
  157. # Debian / Ubuntu
  158. sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libudns-dev
  159. # CentOS / Fedora / RHEL
  160. sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto udns-devel libev-devel
  161. # Arch
  162. sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto udns libev
  163. ./autogen.sh && ./configure && make
  164. sudo make install
  165. ```
  166. ### FreeBSD
  167. ```bash
  168. su
  169. cd /usr/ports/net/shadowsocks-libev
  170. make install
  171. ```
  172. Edit your config.json file. By default, it's located in /usr/local/etc/shadowsocks-libev.
  173. To enable shadowsocks-libev, add the following rc variable to your /etc/rc.conf file:
  174. ```
  175. shadowsocks_libev_enable="YES"
  176. ```
  177. Start the Shadowsocks server:
  178. ```bash
  179. service shadowsocks_libev start
  180. ```
  181. ### OpenWRT
  182. The OpenWRT project is maintained here:
  183. [openwrt-shadowsocks](https://github.com/shadowsocks/openwrt-shadowsocks).
  184. ### OS X
  185. For OS X, use [Homebrew](http://brew.sh) to install or build.
  186. Install Homebrew:
  187. ```bash
  188. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  189. ```
  190. Install shadowsocks-libev:
  191. ```bash
  192. brew install shadowsocks-libev
  193. ```
  194. ## Usage
  195. For a detailed and complete list of all supported arguments, you may refer to the
  196. man pages of the applications, respectively.
  197. ```
  198. ss-[local|redir|server|tunnel]
  199. -s <server_host> host name or ip address of your remote server
  200. -p <server_port> port number of your remote server
  201. -l <local_port> port number of your local server
  202. -k <password> password of your remote server
  203. -m <encrypt_method> Encrypt method: rc4-md5,
  204. aes-128-gcm, aes-192-gcm, aes-256-gcm,
  205. aes-128-cfb, aes-192-cfb, aes-256-cfb,
  206. aes-128-ctr, aes-192-ctr, aes-256-ctr,
  207. camellia-128-cfb, camellia-192-cfb,
  208. camellia-256-cfb, bf-cfb,
  209. chacha20-poly1305, chacha20-ietf-poly1305
  210. salsa20, chacha20 and chacha20-ietf.
  211. [-f <pid_file>] the file path to store pid
  212. [-t <timeout>] socket timeout in seconds
  213. [-c <config_file>] the path to config file
  214. [-i <interface>] network interface to bind,
  215. not available in redir mode
  216. [-b <local_address>] local address to bind,
  217. not available in server mode
  218. [-u] enable udprelay mode,
  219. TPROXY is required in redir mode
  220. [-U] enable UDP relay and disable TCP relay,
  221. not available in local mode
  222. [-L <addr>:<port>] specify destination server address and port
  223. for local port forwarding,
  224. only available in tunnel mode
  225. [-d <addr>] setup name servers for internal DNS resolver,
  226. only available in server mode
  227. [--fast-open] enable TCP fast open,
  228. only available in local and server mode,
  229. with Linux kernel > 3.7.0
  230. [--acl <acl_file>] config file of ACL (Access Control List)
  231. only available in local and server mode
  232. [--manager-address <addr>] UNIX domain socket address
  233. only available in server and manager mode
  234. [--executable <path>] path to the executable of ss-server
  235. only available in manager mode
  236. [--plugin <name>] Enable SIP003 plugin. (Experimental)
  237. [--plugin-opts <options>] Set SIP003 plugin options. (Experimental)
  238. [-v] verbose mode
  239. notes:
  240. ss-redir provides a transparent proxy function and only works on the
  241. Linux platform with iptables.
  242. ```
  243. ## Advanced usage
  244. The latest shadowsocks-libev has provided a *redir* mode. You can configure your Linux-based box or router to proxy all TCP traffic transparently.
  245. # Create new chain
  246. root@Wrt:~# iptables -t nat -N SHADOWSOCKS
  247. root@Wrt:~# iptables -t mangle -N SHADOWSOCKS
  248. root@Wrt:~# iptables -t mangle -N SHADOWSOCKS_MARK
  249. # Ignore your shadowsocks server's addresses
  250. # It's very IMPORTANT, just be careful.
  251. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
  252. # Ignore LANs and any other addresses you'd like to bypass the proxy
  253. # See Wikipedia and RFC5735 for full list of reserved networks.
  254. # See ashi009/bestroutetb for a highly optimized CHN route list.
  255. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
  256. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
  257. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
  258. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
  259. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
  260. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
  261. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
  262. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
  263. # Anything else should be redirected to shadowsocks's local port
  264. root@Wrt:~# iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
  265. # Add any UDP rules
  266. root@Wrt:~# ip route add local default dev lo table 100
  267. root@Wrt:~# ip rule add fwmark 1 lookup 100
  268. root@Wrt:~# iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
  269. root@Wrt:~# iptables -t mangle -A SHADOWSOCKS_MARK -p udp --dport 53 -j MARK --set-mark 1
  270. # Apply the rules
  271. root@Wrt:~# iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS
  272. root@Wrt:~# iptables -t mangle -A PREROUTING -j SHADOWSOCKS
  273. root@Wrt:~# iptables -t mangle -A OUTPUT -j SHADOWSOCKS_MARK
  274. # Start the shadowsocks-redir
  275. root@Wrt:~# ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
  276. ## Shadowsocks over KCP
  277. It's quite easy to use shadowsocks and [KCP](https://github.com/skywind3000/kcp) together with [kcptun](https://github.com/xtaci/kcptun).
  278. 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.
  279. ### Setup your server
  280. ```bash
  281. server_linux_amd64 -l :21 -t 127.0.0.1:443 --crypt none --mtu 1200 --nocomp --mode normal --dscp 46 &
  282. ss-server -s 0.0.0.0 -p 443 -k passwd -m chacha20 -u
  283. ```
  284. ### Setup your client
  285. ```bash
  286. client_linux_amd64 -l 127.0.0.1:1090 -r <server_ip>:21 --crypt none --mtu 1200 --nocomp --mode normal --dscp 46 &
  287. ss-local -s 127.0.0.1 -p 1090 -k passwd -m chacha20 -l 1080 -b 0.0.0.0 &
  288. ss-local -s <server_ip> -p 443 -k passwd -m chacha20 -l 1080 -U -b 0.0.0.0
  289. ```
  290. ## Security Tips
  291. Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend
  292. setting up your server's firewall rules to limit connections from each user:
  293. # Up to 32 connections are enough for normal usage
  294. iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
  295. ## License
  296. ```
  297. Copyright: 2013-2015, Clow Windy <clowwindy42@gmail.com>
  298. 2013-2017, Max Lv <max.c.lv@gmail.com>
  299. 2014, Linus Yang <linusyang@gmail.com>
  300. This program is free software: you can redistribute it and/or modify
  301. it under the terms of the GNU General Public License as published by
  302. the Free Software Foundation, either version 3 of the License, or
  303. (at your option) any later version.
  304. This program is distributed in the hope that it will be useful,
  305. but WITHOUT ANY WARRANTY; without even the implied warranty of
  306. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  307. GNU General Public License for more details.
  308. You should have received a copy of the GNU General Public License
  309. along with this program. If not, see <http://www.gnu.org/licenses/>.
  310. ```