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.

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