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.

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