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.

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