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.

534 lines
19 KiB

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