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.

511 lines
18 KiB

9 years ago
12 years ago
5 years ago
9 years ago
11 years ago
11 years ago
11 years ago
4 years ago
9 years ago
9 years ago
12 years ago
7 years ago
11 years ago
12 years ago
7 years ago
7 years ago
7 years ago
7 years ago
4 years ago
9 years ago
8 years ago
4 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
11 years ago
11 years ago
11 years ago
8 years ago
11 years ago
9 years ago
9 years ago
11 years ago
10 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
7 years ago
5 years ago
7 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
5 years ago
5 years ago
11 years ago
11 years ago
11 years ago
7 years ago
6 years ago
11 years ago
7 years ago
  1. # shadowsocks-libev
  2. [![Build Status](https://travis-ci.com/shadowsocks/shadowsocks-libev.svg?branch=master)](https://travis-ci.com/shadowsocks/shadowsocks-libev) [![Snap Status](https://build.snapcraft.io/badge/shadowsocks/shadowsocks-libev.svg)](https://build.snapcraft.io/user/shadowsocks/shadowsocks-libev)
  3. ## Intro
  4. [Shadowsocks-libev](https://shadowsocks.org) is a lightweight secured SOCKS5
  5. proxy for embedded devices and low-end boxes.
  6. It is a port of [Shadowsocks](https://github.com/shadowsocks/shadowsocks)
  7. created by [@clowwindy](https://github.com/clowwindy), and maintained by
  8. [@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang).
  9. Current version: 3.3.4 | [Changelog](debian/changelog)
  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 lightweight 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. ## Quick Start
  16. Snap is the recommended way to install the latest binaries.
  17. ### Install snap core
  18. https://snapcraft.io/core
  19. ### Install from snapcraft.io
  20. Stable channel:
  21. ```bash
  22. sudo snap install shadowsocks-libev
  23. ```
  24. Edge channel:
  25. ```bash
  26. sudo snap install shadowsocks-libev --edge
  27. ```
  28. ## Installation
  29. ### Distribution-specific guide
  30. - [Debian & Ubuntu](#debian--ubuntu)
  31. + [Install from repository](#install-from-repository)
  32. + [Build deb package from source](#build-deb-package-from-source)
  33. + [Configure and start the service](#configure-and-start-the-service)
  34. - [Fedora & RHEL](#fedora--rhel)
  35. + [Build from source with centos](#build-from-source-with-centos)
  36. - [Archlinux & Manjaro](#archlinux--manjaro)
  37. - [NixOS](#nixos)
  38. - [Nix](#nix)
  39. - [Directly build and install on UNIX-like system](#linux)
  40. - [FreeBSD](#freebsd)
  41. + [Install](#install)
  42. + [Configuration](#configuration)
  43. + [Run](#run)
  44. + [Run as client](#run-as-client)
  45. - [OpenWRT](#openwrt)
  46. - [OS X](#os-x)
  47. - [Windows (MinGW)](#windows-mingw)
  48. - [Docker](#docker)
  49. * * *
  50. ### Pre-build configure guide
  51. For a complete list of available configure-time option,
  52. try `configure --help`.
  53. ### Debian & Ubuntu
  54. #### Install from repository (not recommended)
  55. Shadowsocks-libev is available in the official repository for following distributions:
  56. * Debian 8 or higher, including oldoldstable (jessie), old stable (stretch), stable (buster), testing (bullseye) and unstable (sid)
  57. * Ubuntu 16.10 or higher
  58. ```bash
  59. sudo apt update
  60. sudo apt install shadowsocks-libev
  61. ```
  62. #### Build deb package from source
  63. Supported distributions:
  64. * Debian 8, 9 or higher
  65. * Ubuntu 14.04 LTS, 16.04 LTS, 16.10 or higher
  66. You can build shadowsocks-libev and all its dependencies by script:
  67. ```bash
  68. mkdir -p ~/build-area/
  69. cp ./scripts/build_deb.sh ~/build-area/
  70. cd ~/build-area
  71. ./build_deb.sh
  72. ```
  73. For older systems, building `.deb` packages is not supported.
  74. Please try to build and install directly from source. See the [Linux](#linux) section below.
  75. **Note for Debian 8 (Jessie) users to build their own deb packages**:
  76. We strongly encourage you to install shadowsocks-libev from `jessie-backports-sloppy`. If you insist on building from source, you will need to manually install libsodium from `jessie-backports-sloppy`, **NOT** libsodium in main repository.
  77. For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
  78. ``` bash
  79. cd shadowsocks-libev
  80. sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list'
  81. sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports-sloppy main" >> /etc/apt/sources.list.d/jessie-backports.list'
  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. **Note for Debian 9 (Stretch) users to build their own deb packages**:
  89. We strongly encourage you to install shadowsocks-libev from `stretch-backports`. If you insist on building from source, you will need to manually install libsodium from `stretch-backports`, **NOT** libsodium in main repository.
  90. For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
  91. ``` bash
  92. cd shadowsocks-libev
  93. sudo sh -c 'printf "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-backports.list'
  94. sudo apt-get install --no-install-recommends devscripts equivs
  95. mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
  96. ./autogen.sh && dpkg-buildpackage -b -us -uc
  97. cd ..
  98. sudo dpkg -i shadowsocks-libev*.deb
  99. ```
  100. #### Configure and start the service
  101. ```
  102. # Edit the configuration file
  103. sudo vim /etc/shadowsocks-libev/config.json
  104. # Edit the default configuration for debian
  105. sudo vim /etc/default/shadowsocks-libev
  106. # Start the service
  107. sudo /etc/init.d/shadowsocks-libev start # for sysvinit, or
  108. sudo systemctl start shadowsocks-libev # for systemd
  109. ```
  110. ### Fedora & RHEL
  111. Supported distributions:
  112. * Recent Fedora versions (until EOL)
  113. * RHEL 6, 7 and derivatives (including CentOS, Scientific Linux)
  114. #### Build from source with centos
  115. If you are using CentOS 7, you need to install these prerequirements to build from source code:
  116. ```bash
  117. yum install epel-release -y
  118. yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
  119. ```
  120. ### Archlinux & Manjaro
  121. ```bash
  122. sudo pacman -S shadowsocks-libev
  123. ```
  124. Please refer to downstream [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/trunk?h=packages/shadowsocks-libev)
  125. script for extra modifications and distribution-specific bugs.
  126. ### NixOS
  127. ```bash
  128. nix-env -iA nixos.shadowsocks-libev
  129. ```
  130. ### Nix
  131. ```bash
  132. nix-env -iA nixpkgs.shadowsocks-libev
  133. ```
  134. ### Linux
  135. In general, you need the following build dependencies:
  136. * autotools (autoconf, automake, libtool)
  137. * gettext
  138. * pkg-config
  139. * libmbedtls
  140. * libsodium
  141. * libpcre3 (old pcre library)
  142. * libev
  143. * libc-ares
  144. * asciidoc (for documentation only)
  145. * xmlto (for documentation only)
  146. Notes: Fedora 26 libsodium version >= 1.0.12, so you can install via dnf install libsodium instead build from source.
  147. 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.
  148. 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.
  149. For some of the distributions, you might install build dependencies like this:
  150. ```bash
  151. # Installation of basic build dependencies
  152. ## Debian / Ubuntu
  153. sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto libev-dev libc-ares-dev automake libmbedtls-dev libsodium-dev
  154. ## CentOS / Fedora / RHEL
  155. sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel
  156. ## Arch
  157. sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto c-ares libev
  158. # Installation of libsodium
  159. export LIBSODIUM_VER=1.0.16
  160. wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
  161. tar xvf libsodium-$LIBSODIUM_VER.tar.gz
  162. pushd libsodium-$LIBSODIUM_VER
  163. ./configure --prefix=/usr && make
  164. sudo make install
  165. popd
  166. sudo ldconfig
  167. # Installation of MbedTLS
  168. export MBEDTLS_VER=2.6.0
  169. wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
  170. tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
  171. pushd mbedtls-$MBEDTLS_VER
  172. make SHARED=1 CFLAGS="-O2 -fPIC"
  173. sudo make DESTDIR=/usr install
  174. popd
  175. sudo ldconfig
  176. # Start building
  177. ./autogen.sh && ./configure && make
  178. sudo make install
  179. ```
  180. You may need to manually install missing softwares.
  181. ### FreeBSD
  182. #### Install
  183. Shadowsocks-libev is available in FreeBSD Ports Collection. You can install it in either way, `pkg` or `ports`.
  184. **pkg (recommended)**
  185. ```bash
  186. pkg install shadowsocks-libev
  187. ```
  188. **ports**
  189. ```bash
  190. cd /usr/ports/net/shadowsocks-libev
  191. make install
  192. ```
  193. #### Configuration
  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. #### Run
  200. Start the Shadowsocks server:
  201. ```bash
  202. service shadowsocks_libev start
  203. ```
  204. #### Run as client
  205. By default, shadowsocks-libev is running as a server in FreeBSD. If you would like to start shadowsocks-libev in client mode, you can modify the rc script (`/usr/local/etc/rc.d/shadowsocks_libev`) manually.
  206. ```
  207. # modify the following line from "ss-server" to "ss-local"
  208. command="/usr/local/bin/ss-local"
  209. ```
  210. Note that is simply a workaround, each time you upgrade the port your changes will be overwritten by the new version.
  211. ### OpenWRT
  212. The OpenWRT project is maintained here:
  213. [openwrt-shadowsocks](https://github.com/shadowsocks/openwrt-shadowsocks).
  214. ### OS X
  215. For OS X, use [Homebrew](http://brew.sh) to install or build.
  216. Install Homebrew:
  217. ```bash
  218. ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  219. ```
  220. Install shadowsocks-libev:
  221. ```bash
  222. brew install shadowsocks-libev
  223. ```
  224. ### Windows (MinGW)
  225. To build Windows native binaries, the recommended method is to use Docker:
  226. * On Windows: double-click `make.bat` in `docker\mingw`
  227. * On Unix-like system:
  228. cd shadowsocks-libev/docker/mingw
  229. make
  230. A tarball with 32-bit and 64-bit binaries will be generated in the same directory.
  231. You could also manually use MinGW-w64 compilers to build in Unix-like shell (MSYS2/Cygwin), or cross-compile on Unix-like systems (Linux/MacOS). Please refer to build scripts in `docker/mingw`.
  232. Currently you need to use a patched libev library for MinGW:
  233. * https://github.com/shadowsocks/libev/archive/mingw.zip
  234. Notice that TCP Fast Open (TFO) is only available on **Windows 10**, **1607** or later version (precisely, build >= 14393). If you are using **1709** (build 16299) or later version, you also need to run the following command in PowerShell/Command Prompt **as Administrator** and **reboot** to use TFO properly:
  235. netsh int tcp set global fastopenfallback=disabled
  236. ### Docker
  237. As you expect, simply pull the image and run.
  238. ```
  239. docker pull shadowsocks/shadowsocks-libev
  240. docker run -e PASSWORD=<password> -p<server-port>:8388 -p<server-port>:8388/udp -d shadowsocks/shadowsocks-libev
  241. ```
  242. More information about the image can be found [here](docker/alpine/README.md).
  243. ## Usage
  244. For a detailed and complete list of all supported arguments,
  245. you may refer to the man pages of the applications, respectively.
  246. ss-[local|redir|server|tunnel|manager]
  247. -s <server_host> Host name or IP address of your remote server.
  248. -p <server_port> Port number of your remote server.
  249. -l <local_port> Port number of your local server.
  250. -k <password> Password of your remote server.
  251. -m <encrypt_method> Encrypt method: rc4-md5,
  252. aes-128-gcm, aes-192-gcm, aes-256-gcm,
  253. aes-128-cfb, aes-192-cfb, aes-256-cfb,
  254. aes-128-ctr, aes-192-ctr, aes-256-ctr,
  255. camellia-128-cfb, camellia-192-cfb,
  256. camellia-256-cfb, bf-cfb,
  257. chacha20-ietf-poly1305,
  258. xchacha20-ietf-poly1305,
  259. salsa20, chacha20 and chacha20-ietf.
  260. The default cipher is chacha20-ietf-poly1305.
  261. [-a <user>] Run as another user.
  262. [-f <pid_file>] The file path to store pid.
  263. [-t <timeout>] Socket timeout in seconds.
  264. [-c <config_file>] The path to config file.
  265. [-n <number>] Max number of open files.
  266. [-i <interface>] Network interface to bind.
  267. (not available in redir mode)
  268. [-b <local_address>] Local address to bind.
  269. For servers: Specify the local address to use
  270. while this server is making outbound
  271. connections to remote servers on behalf of the
  272. clients.
  273. For clients: Specify the local address to use
  274. while this client is making outbound
  275. connections to the server.
  276. [-u] Enable UDP relay.
  277. (TPROXY is required in redir mode)
  278. [-U] Enable UDP relay and disable TCP relay.
  279. (not available in local mode)
  280. [-L <addr>:<port>] Destination server address and port
  281. for local port forwarding.
  282. (only available in tunnel mode)
  283. [-6] Resolve hostname to IPv6 address first.
  284. [-d <addr>] Name servers for internal DNS resolver.
  285. (only available in server mode)
  286. [--reuse-port] Enable port reuse.
  287. [--fast-open] Enable TCP fast open.
  288. with Linux kernel > 3.7.0.
  289. (only available in local and server mode)
  290. [--acl <acl_file>] Path to ACL (Access Control List).
  291. (only available in local and server mode)
  292. [--manager-address <addr>] UNIX domain socket address.
  293. (only available in server and manager mode)
  294. [--mtu <MTU>] MTU of your network interface.
  295. [--mptcp] Enable Multipath TCP on MPTCP Kernel.
  296. [--no-delay] Enable TCP_NODELAY.
  297. [--executable <path>] Path to the executable of ss-server.
  298. (only available in manager mode)
  299. [-D <path>] Path to the working directory of ss-manager.
  300. (only available in manager mode)
  301. [--key <key_in_base64>] Key of your remote server.
  302. [--plugin <name>] Enable SIP003 plugin. (Experimental)
  303. [--plugin-opts <options>] Set SIP003 plugin options. (Experimental)
  304. [-v] Verbose mode.
  305. ## Transparent proxy
  306. The latest shadowsocks-libev has provided a *redir* mode. You can configure your Linux-based box or router to proxy all TCP traffic transparently, which is handy if you use an OpenWRT-powered router.
  307. # Create new chain
  308. iptables -t nat -N SHADOWSOCKS
  309. iptables -t mangle -N SHADOWSOCKS
  310. # Ignore your shadowsocks server's addresses
  311. # It's very IMPORTANT, just be careful.
  312. iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
  313. # Ignore LANs and any other addresses you'd like to bypass the proxy
  314. # See Wikipedia and RFC5735 for full list of reserved networks.
  315. # See ashi009/bestroutetb for a highly optimized CHN route list.
  316. iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
  317. iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
  318. iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
  319. iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
  320. iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
  321. iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
  322. iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
  323. iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
  324. # Anything else should be redirected to shadowsocks's local port
  325. iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
  326. # Add any UDP rules
  327. ip route add local default dev lo table 100
  328. ip rule add fwmark 1 lookup 100
  329. iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
  330. # Apply the rules
  331. iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS
  332. iptables -t mangle -A PREROUTING -j SHADOWSOCKS
  333. # Start the shadowsocks-redir
  334. ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
  335. ## Security Tips
  336. For any public server, to avoid users accessing localhost of your server, please add `--acl acl/server_block_local.acl` to the command line.
  337. Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend
  338. setting up your server's firewall rules to limit connections from each user:
  339. # Up to 32 connections are enough for normal usage
  340. iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
  341. ## License
  342. ```
  343. Copyright: 2013-2015, Clow Windy <clowwindy42@gmail.com>
  344. 2013-2018, Max Lv <max.c.lv@gmail.com>
  345. 2014, Linus Yang <linusyang@gmail.com>
  346. This program is free software: you can redistribute it and/or modify
  347. it under the terms of the GNU General Public License as published by
  348. the Free Software Foundation, either version 3 of the License, or
  349. (at your option) any later version.
  350. This program is distributed in the hope that it will be useful,
  351. but WITHOUT ANY WARRANTY; without even the implied warranty of
  352. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  353. GNU General Public License for more details.
  354. You should have received a copy of the GNU General Public License
  355. along with this program. If not, see <http://www.gnu.org/licenses/>.
  356. ```