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.

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