• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.copr/H15-Sep-2020-2015

.github/H15-Sep-2020-6848

acl/H15-Sep-2020-17,43717,427

build/H15-Sep-2020-

cmake/H15-Sep-2020-517389

completions/H15-Sep-2020-345315

debian/H15-Sep-2020-1,432973

doc/H03-May-2022-1,4131,110

docker/H15-Sep-2020-579363

libbloom/H03-May-2022-1,252753

libcork/H03-May-2022-26,48218,733

libipset/H03-May-2022-10,8547,248

m4/H15-Sep-2020-982868

rpm/H15-Sep-2020-624476

scripts/H15-Sep-2020-779642

snap/H15-Sep-2020-7059

src/H03-May-2022-19,80915,203

tests/H15-Sep-2020-282227

.dockerignoreH A D15-Sep-2020280 2824

.gitignoreH A D15-Sep-20201.2 KiB10092

.gitmodulesH A D15-Sep-2020324 1312

.travis.ymlH A D15-Sep-20201.8 KiB6463

.uncrustify.cfgH A D15-Sep-202060 KiB1,377971

AUTHORSH A D15-Sep-2020420 107

COPYINGH A D15-Sep-2020613 1310

ChangesH A D15-Sep-202016 KiB603327

INSTALLH A D15-Sep-202015.2 KiB366284

LICENSEH A D15-Sep-202031.7 KiB623513

Makefile.amH A D03-May-2022523 2116

README.mdH A D15-Sep-202023.4 KiB666481

autogen.shH A D15-Sep-202040 41

configure.acH A D03-May-20227.9 KiB275240

shadowsocks-libev.pc.inH A D15-Sep-2020275 1311

README.md

1# shadowsocks-libev
2
3[![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)
4
5## Intro
6
7[Shadowsocks-libev](https://shadowsocks.org) is a lightweight secured SOCKS5
8proxy for embedded devices and low-end boxes.
9
10It is a port of [Shadowsocks](https://github.com/shadowsocks/shadowsocks)
11created by [@clowwindy](https://github.com/clowwindy), and maintained by
12[@madeye](https://github.com/madeye) and [@linusyang](https://github.com/linusyang).
13
14Current version: 3.3.5 | [Changelog](debian/changelog)
15
16## Features
17
18Shadowsocks-libev is written in pure C and depends on [libev](http://software.schmorp.de/pkg/libev.html). It's designed
19to be a lightweight implementation of shadowsocks protocol, in order to keep the resource usage as low as possible.
20
21For a full list of feature comparison between different versions of shadowsocks,
22refer to the [Wiki page](https://github.com/shadowsocks/shadowsocks/wiki/Feature-Comparison-across-Different-Versions).
23
24## Quick Start
25
26Snap is the recommended way to install the latest binaries.
27
28### Install snap core
29
30https://snapcraft.io/core
31
32### Install from snapcraft.io
33
34Stable channel:
35
36```bash
37sudo snap install shadowsocks-libev
38```
39
40Edge channel:
41
42```bash
43sudo snap install shadowsocks-libev --edge
44```
45
46## Installation
47
48### Distribution-specific guide
49
50- [Debian & Ubuntu](#debian--ubuntu)
51    + [Install from repository](#install-from-repository-not-recommended)
52    + [Build deb package from source](#build-deb-package-from-source)
53    + [Configure and start the service](#configure-and-start-the-service)
54- [Fedora & RHEL](#fedora--rhel)
55    + [Build from source with centos](#build-from-source-with-centos)
56- [Archlinux & Manjaro](#archlinux--manjaro)
57- [NixOS](#nixos)
58- [Nix](#nix)
59- [Directly build and install on UNIX-like system](#linux)
60- [FreeBSD](#freebsd)
61    + [Install](#install)
62    + [Configuration](#configuration)
63    + [Run](#run)
64    + [Run as client](#run-as-client)
65- [OpenWRT](#openwrt)
66- [OS X](#os-x)
67- [Windows (MinGW)](#windows-mingw)
68- [Docker](#docker)
69
70* * *
71
72### Pre-build configure guide
73
74For a complete list of available configure-time option,
75try `configure --help`.
76
77### Debian & Ubuntu
78
79#### Install from repository (not recommended)
80
81Shadowsocks-libev is available in the official repository for following distributions:
82
83* Debian 8 or higher, including oldoldstable (jessie), old stable (stretch), stable (buster), testing (bullseye) and unstable (sid)
84* Ubuntu 16.10 or higher
85
86```bash
87sudo apt update
88sudo apt install shadowsocks-libev
89```
90
91#### Build deb package from source
92
93Supported distributions:
94
95* Debian 8, 9 or higher
96* Ubuntu 14.04 LTS, 16.04 LTS, 16.10 or higher
97
98You can build shadowsocks-libev and all its dependencies by script:
99
100```bash
101mkdir -p ~/build-area/
102cp ./scripts/build_deb.sh ~/build-area/
103cd ~/build-area
104./build_deb.sh
105```
106
107For older systems, building `.deb` packages is not supported.
108Please try to build and install directly from source. See the [Linux](#linux) section below.
109
110**Note for Debian 8 (Jessie) users to build their own deb packages**:
111
112We 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.
113
114For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
115
116``` bash
117cd shadowsocks-libev
118sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list'
119sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports-sloppy main" >> /etc/apt/sources.list.d/jessie-backports.list'
120sudo apt-get install --no-install-recommends devscripts equivs
121mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
122./autogen.sh && dpkg-buildpackage -b -us -uc
123cd ..
124sudo dpkg -i shadowsocks-libev*.deb
125```
126
127**Note for Debian 9 (Stretch) users to build their own deb packages**:
128
129We 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.
130
131For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
132
133``` bash
134cd shadowsocks-libev
135sudo sh -c 'printf "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-backports.list'
136sudo apt-get install --no-install-recommends devscripts equivs
137mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
138./autogen.sh && dpkg-buildpackage -b -us -uc
139cd ..
140sudo dpkg -i shadowsocks-libev*.deb
141```
142
143#### Configure and start the service
144
145```
146# Edit the configuration file
147sudo vim /etc/shadowsocks-libev/config.json
148
149# Edit the default configuration for debian
150sudo vim /etc/default/shadowsocks-libev
151
152# Start the service
153sudo /etc/init.d/shadowsocks-libev start    # for sysvinit, or
154sudo systemctl start shadowsocks-libev      # for systemd
155```
156
157### Fedora & RHEL
158
159Supported distributions:
160
161* Recent Fedora versions (until EOL)
162* RHEL 6, 7 and derivatives (including CentOS, Scientific Linux)
163
164#### Build from source with centos
165
166If you are using CentOS 7, you need to install these prerequirements to build from source code:
167
168```bash
169yum install epel-release -y
170yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
171```
172
173### Archlinux & Manjaro
174
175```bash
176sudo pacman -S shadowsocks-libev
177```
178
179Please refer to downstream [PKGBUILD](https://projects.archlinux.org/svntogit/community.git/tree/trunk?h=packages/shadowsocks-libev)
180script for extra modifications and distribution-specific bugs.
181
182### NixOS
183
184```bash
185nix-env -iA nixos.shadowsocks-libev
186```
187
188### Nix
189
190```bash
191nix-env -iA nixpkgs.shadowsocks-libev
192```
193
194### Linux
195
196In general, you need the following build dependencies:
197
198* autotools (autoconf, automake, libtool)
199* gettext
200* pkg-config
201* libmbedtls
202* libsodium
203* libpcre3 (old pcre library)
204* libev
205* libc-ares
206* asciidoc (for documentation only)
207* xmlto (for documentation only)
208
209Notes: Fedora 26  libsodium version >= 1.0.12, so you can install via dnf install libsodium instead build from source.
210
211If 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.
212
213If 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.
214
215For some of the distributions, you might install build dependencies like this:
216
217```bash
218# Installation of basic build dependencies
219## Debian / Ubuntu
220sudo 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
221## CentOS / Fedora / RHEL
222sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel
223## Arch
224sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto c-ares libev
225
226# Installation of libsodium
227export LIBSODIUM_VER=1.0.16
228wget https://download.libsodium.org/libsodium/releases/libsodium-$LIBSODIUM_VER.tar.gz
229tar xvf libsodium-$LIBSODIUM_VER.tar.gz
230pushd libsodium-$LIBSODIUM_VER
231./configure --prefix=/usr && make
232sudo make install
233popd
234sudo ldconfig
235
236# Installation of MbedTLS
237export MBEDTLS_VER=2.6.0
238wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
239tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
240pushd mbedtls-$MBEDTLS_VER
241make SHARED=1 CFLAGS="-O2 -fPIC"
242sudo make DESTDIR=/usr install
243popd
244sudo ldconfig
245
246# Start building
247./autogen.sh && ./configure && make
248sudo make install
249```
250
251You may need to manually install missing softwares.
252
253### FreeBSD
254#### Install
255Shadowsocks-libev is available in FreeBSD Ports Collection. You can install it in either way, `pkg` or `ports`.
256
257**pkg (recommended)**
258
259```bash
260pkg install shadowsocks-libev
261```
262
263**ports**
264
265```bash
266cd /usr/ports/net/shadowsocks-libev
267make install
268```
269
270#### Configuration
271Edit your `config.json` file. By default, it's located in `/usr/local/etc/shadowsocks-libev`.
272
273To enable shadowsocks-libev, add the following rc variable to your `/etc/rc.conf` file:
274
275```
276shadowsocks_libev_enable="YES"
277```
278
279#### Run
280
281Start the Shadowsocks server:
282
283```bash
284service shadowsocks_libev start
285```
286
287#### Run as client
288By 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.
289
290```
291# modify the following line from "ss-server" to "ss-local"
292command="/usr/local/bin/ss-local"
293```
294
295Note that is simply a workaround, each time you upgrade the port your changes will be overwritten by the new version.
296
297### OpenWRT
298
299The OpenWRT project is maintained here:
300[openwrt-shadowsocks](https://github.com/shadowsocks/openwrt-shadowsocks).
301
302### OS X
303For OS X, use [Homebrew](http://brew.sh) to install or build.
304
305Install Homebrew:
306
307```bash
308ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
309```
310Install shadowsocks-libev:
311
312```bash
313brew install shadowsocks-libev
314```
315
316### Windows (MinGW)
317To build Windows native binaries, the recommended method is to use Docker:
318
319* On Windows: double-click `make.bat` in `docker\mingw`
320* On Unix-like system:
321
322        cd shadowsocks-libev/docker/mingw
323        make
324
325A tarball with 32-bit and 64-bit binaries will be generated in the same directory.
326
327You 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`.
328
329Currently you need to use a patched libev library for MinGW:
330
331* https://github.com/shadowsocks/libev/archive/mingw.zip
332
333Notice 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:
334
335        netsh int tcp set global fastopenfallback=disabled
336
337### Docker
338
339As you expect, simply pull the image and run.
340```
341docker pull shadowsocks/shadowsocks-libev
342docker run -e PASSWORD=<password> -p<server-port>:8388 -p<server-port>:8388/udp -d shadowsocks/shadowsocks-libev
343```
344
345More information about the image can be found [here](docker/alpine/README.md).
346
347## Usage
348
349For a detailed and complete list of all supported arguments,
350you may refer to the man pages of the applications, respectively.
351
352    ss-[local|redir|server|tunnel|manager]
353
354       -s <server_host>           Host name or IP address of your remote server.
355
356       -p <server_port>           Port number of your remote server.
357
358       -l <local_port>            Port number of your local server.
359
360       -k <password>              Password of your remote server.
361
362       -m <encrypt_method>        Encrypt method: rc4-md5,
363                                  aes-128-gcm, aes-192-gcm, aes-256-gcm,
364                                  aes-128-cfb, aes-192-cfb, aes-256-cfb,
365                                  aes-128-ctr, aes-192-ctr, aes-256-ctr,
366                                  camellia-128-cfb, camellia-192-cfb,
367                                  camellia-256-cfb, bf-cfb,
368                                  chacha20-ietf-poly1305,
369                                  xchacha20-ietf-poly1305,
370                                  salsa20, chacha20 and chacha20-ietf.
371                                  The default cipher is chacha20-ietf-poly1305.
372
373       [-a <user>]                Run as another user.
374
375       [-f <pid_file>]            The file path to store pid.
376
377       [-t <timeout>]             Socket timeout in seconds.
378
379       [-c <config_file>]         The path to config file.
380
381       [-n <number>]              Max number of open files.
382
383       [-i <interface>]           Network interface to bind.
384                                  (not available in redir mode)
385
386       [-b <local_address>]       Local address to bind.
387                                  For servers: Specify the local address to use
388                                  while this server is making outbound
389                                  connections to remote servers on behalf of the
390                                  clients.
391                                  For clients: Specify the local address to use
392                                  while this client is making outbound
393                                  connections to the server.
394
395       [-u]                       Enable UDP relay.
396                                  (TPROXY is required in redir mode)
397
398       [-U]                       Enable UDP relay and disable TCP relay.
399                                  (not available in local mode)
400
401       [-T]                       Use tproxy instead of redirect. (for tcp)
402                                  (only available in redir mode)
403
404       [-L <addr>:<port>]         Destination server address and port
405                                  for local port forwarding.
406                                  (only available in tunnel mode)
407
408       [-6]                       Resolve hostname to IPv6 address first.
409
410       [-d <addr>]                Name servers for internal DNS resolver.
411                                  (only available in server mode)
412
413       [--reuse-port]             Enable port reuse.
414
415       [--fast-open]              Enable TCP fast open.
416                                  with Linux kernel > 3.7.0.
417                                  (only available in local and server mode)
418
419       [--acl <acl_file>]         Path to ACL (Access Control List).
420                                  (only available in local and server mode)
421
422       [--manager-address <addr>] UNIX domain socket address.
423                                  (only available in server and manager mode)
424
425       [--mtu <MTU>]              MTU of your network interface.
426
427       [--mptcp]                  Enable Multipath TCP on MPTCP Kernel.
428
429       [--no-delay]               Enable TCP_NODELAY.
430
431       [--executable <path>]      Path to the executable of ss-server.
432                                  (only available in manager mode)
433
434       [-D <path>]                Path to the working directory of ss-manager.
435                                  (only available in manager mode)
436
437       [--key <key_in_base64>]    Key of your remote server.
438
439       [--plugin <name>]          Enable SIP003 plugin. (Experimental)
440
441       [--plugin-opts <options>]  Set SIP003 plugin options. (Experimental)
442
443       [-v]                       Verbose mode.
444
445## Transparent proxy
446
447The 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.
448
449    # Create new chain
450    iptables -t nat -N SHADOWSOCKS
451    iptables -t mangle -N SHADOWSOCKS
452
453    # Ignore your shadowsocks server's addresses
454    # It's very IMPORTANT, just be careful.
455    iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
456
457    # Ignore LANs and any other addresses you'd like to bypass the proxy
458    # See Wikipedia and RFC5735 for full list of reserved networks.
459    # See ashi009/bestroutetb for a highly optimized CHN route list.
460    iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
461    iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
462    iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
463    iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
464    iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
465    iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
466    iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
467    iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
468
469    # Anything else should be redirected to shadowsocks's local port
470    iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
471
472    # Add any UDP rules
473    ip route add local default dev lo table 100
474    ip rule add fwmark 1 lookup 100
475    iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
476
477    # Apply the rules
478    iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS
479    iptables -t mangle -A PREROUTING -j SHADOWSOCKS
480
481    # Start the shadowsocks-redir
482    ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
483
484## Transparent proxy (pure tproxy)
485
486Executing this script on the linux host can proxy all outgoing traffic of this machine (except the traffic sent to the reserved address). Other hosts under the same LAN can also change their default gateway to the ip of this linux host (at the same time change the dns server to 1.1.1.1 or 8.8.8.8, etc.) to proxy their outgoing traffic.
487
488> Of course, the ipv6 proxy is similar, just change `iptables` to `ip6tables`, `ip` to `ip -6`, `127.0.0.1` to `::1`, and other details.
489
490```shell
491#!/bin/bash
492
493start_ssredir() {
494    # please modify MyIP, MyPort, etc.
495    (ss-redir -s MyIP -p MyPort -m MyMethod -k MyPasswd -b 127.0.0.1 -l 60080 --no-delay -u -T -v </dev/null &>>/var/log/ss-redir.log &)
496}
497
498stop_ssredir() {
499    kill -9 $(pidof ss-redir) &>/dev/null
500}
501
502start_iptables() {
503    ##################### SSREDIR #####################
504    iptables -t mangle -N SSREDIR
505
506    # connection-mark -> packet-mark
507    iptables -t mangle -A SSREDIR -j CONNMARK --restore-mark
508    iptables -t mangle -A SSREDIR -m mark --mark 0x2333 -j RETURN
509
510    # please modify MyIP, MyPort, etc.
511    # ignore traffic sent to ss-server
512    iptables -t mangle -A SSREDIR -p tcp -d MyIP --dport MyPort -j RETURN
513    iptables -t mangle -A SSREDIR -p udp -d MyIP --dport MyPort -j RETURN
514
515    # ignore traffic sent to reserved addresses
516    iptables -t mangle -A SSREDIR -d 0.0.0.0/8          -j RETURN
517    iptables -t mangle -A SSREDIR -d 10.0.0.0/8         -j RETURN
518    iptables -t mangle -A SSREDIR -d 100.64.0.0/10      -j RETURN
519    iptables -t mangle -A SSREDIR -d 127.0.0.0/8        -j RETURN
520    iptables -t mangle -A SSREDIR -d 169.254.0.0/16     -j RETURN
521    iptables -t mangle -A SSREDIR -d 172.16.0.0/12      -j RETURN
522    iptables -t mangle -A SSREDIR -d 192.0.0.0/24       -j RETURN
523    iptables -t mangle -A SSREDIR -d 192.0.2.0/24       -j RETURN
524    iptables -t mangle -A SSREDIR -d 192.88.99.0/24     -j RETURN
525    iptables -t mangle -A SSREDIR -d 192.168.0.0/16     -j RETURN
526    iptables -t mangle -A SSREDIR -d 198.18.0.0/15      -j RETURN
527    iptables -t mangle -A SSREDIR -d 198.51.100.0/24    -j RETURN
528    iptables -t mangle -A SSREDIR -d 203.0.113.0/24     -j RETURN
529    iptables -t mangle -A SSREDIR -d 224.0.0.0/4        -j RETURN
530    iptables -t mangle -A SSREDIR -d 240.0.0.0/4        -j RETURN
531    iptables -t mangle -A SSREDIR -d 255.255.255.255/32 -j RETURN
532
533    # mark the first packet of the connection
534    iptables -t mangle -A SSREDIR -p tcp --syn                      -j MARK --set-mark 0x2333
535    iptables -t mangle -A SSREDIR -p udp -m conntrack --ctstate NEW -j MARK --set-mark 0x2333
536
537    # packet-mark -> connection-mark
538    iptables -t mangle -A SSREDIR -j CONNMARK --save-mark
539
540    ##################### OUTPUT #####################
541    # proxy the outgoing traffic from this machine
542    iptables -t mangle -A OUTPUT -p tcp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR
543    iptables -t mangle -A OUTPUT -p udp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR
544
545    ##################### PREROUTING #####################
546    # proxy traffic passing through this machine (other->other)
547    iptables -t mangle -A PREROUTING -p tcp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR
548    iptables -t mangle -A PREROUTING -p udp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR
549
550    # hand over the marked package to TPROXY for processing
551    iptables -t mangle -A PREROUTING -p tcp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080
552    iptables -t mangle -A PREROUTING -p udp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080
553}
554
555stop_iptables() {
556    ##################### PREROUTING #####################
557    iptables -t mangle -D PREROUTING -p tcp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 &>/dev/null
558    iptables -t mangle -D PREROUTING -p udp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 &>/dev/null
559
560    iptables -t mangle -D PREROUTING -p tcp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR &>/dev/null
561    iptables -t mangle -D PREROUTING -p udp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR &>/dev/null
562
563    ##################### OUTPUT #####################
564    iptables -t mangle -D OUTPUT -p tcp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR &>/dev/null
565    iptables -t mangle -D OUTPUT -p udp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR &>/dev/null
566
567    ##################### SSREDIR #####################
568    iptables -t mangle -F SSREDIR &>/dev/null
569    iptables -t mangle -X SSREDIR &>/dev/null
570}
571
572start_iproute2() {
573    ip route add local default dev lo table 100
574    ip rule  add fwmark 0x2333        table 100
575}
576
577stop_iproute2() {
578    ip rule  del   table 100 &>/dev/null
579    ip route flush table 100 &>/dev/null
580}
581
582start_resolvconf() {
583    # or nameserver 8.8.8.8, etc.
584    echo "nameserver 1.1.1.1" >/etc/resolv.conf
585}
586
587stop_resolvconf() {
588    echo "nameserver 114.114.114.114" >/etc/resolv.conf
589}
590
591start() {
592    echo "start ..."
593    start_ssredir
594    start_iptables
595    start_iproute2
596    start_resolvconf
597    echo "start end"
598}
599
600stop() {
601    echo "stop ..."
602    stop_resolvconf
603    stop_iproute2
604    stop_iptables
605    stop_ssredir
606    echo "stop end"
607}
608
609restart() {
610    stop
611    sleep 1
612    start
613}
614
615main() {
616    if [ $# -eq 0 ]; then
617        echo "usage: $0 start|stop|restart ..."
618        return 1
619    fi
620
621    for funcname in "$@"; do
622        if [ "$(type -t $funcname)" != 'function' ]; then
623            echo "'$funcname' not a shell function"
624            return 1
625        fi
626    done
627
628    for funcname in "$@"; do
629        $funcname
630    done
631    return 0
632}
633main "$@"
634```
635
636## Security Tips
637
638For any public server, to avoid users accessing localhost of your server, please add `--acl acl/server_block_local.acl` to the command line.
639
640Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend
641setting up your server's firewall rules to limit connections from each user:
642
643    # Up to 32 connections are enough for normal usage
644    iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
645
646## License
647
648```
649Copyright: 2013-2015, Clow Windy <clowwindy42@gmail.com>
650           2013-2018, Max Lv <max.c.lv@gmail.com>
651           2014, Linus Yang <linusyang@gmail.com>
652
653This program is free software: you can redistribute it and/or modify
654it under the terms of the GNU General Public License as published by
655the Free Software Foundation, either version 3 of the License, or
656(at your option) any later version.
657
658This program is distributed in the hope that it will be useful,
659but WITHOUT ANY WARRANTY; without even the implied warranty of
660MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
661GNU General Public License for more details.
662
663You should have received a copy of the GNU General Public License
664along with this program. If not, see <http://www.gnu.org/licenses/>.
665```
666