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.

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