Skip to content

Commit 5c47b80

Browse files
madeyeclaude
andcommitted
Update README with CMake build instructions and ss-setup/ss-nat docs
Modernize build instructions to focus on CMake (the sole build system), remove outdated autotools/backports references, and add documentation for the ss-setup interactive TUI tool and the ss-nat transparent proxy helper script with practical usage examples. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c5e8788 commit 5c47b80

1 file changed

Lines changed: 213 additions & 86 deletions

File tree

README.md

Lines changed: 213 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,48 @@ sudo snap install shadowsocks-libev --edge
6969

7070
* * *
7171

72-
### Initialise the build environment
72+
### Build from source (CMake)
7373

74-
This repository uses submodules, so you should pull them before you start, using:
74+
shadowsocks-libev uses CMake as its sole build system. Start by pulling submodules:
7575

7676
```bash
7777
git submodule update --init --recursive
7878
```
7979

80-
### Pre-build configure guide
80+
Then build:
8181

82-
For a complete list of available configure-time options,
83-
try `cmake -LH` from a build directory.
82+
```bash
83+
mkdir -p build && cd build
84+
cmake ..
85+
make
86+
sudo make install
87+
```
88+
89+
To run unit tests:
90+
91+
```bash
92+
cd build
93+
ctest --output-on-failure
94+
```
95+
96+
#### CMake options
97+
98+
For a complete list of available options, run `cmake -LH` from a build directory.
99+
Commonly used options:
100+
101+
| Option | Default | Description |
102+
|---|---|---|
103+
| `-DWITH_EMBEDDED_SRC=OFF` | `ON` | Use system libcork/libipset/libbloom instead of bundled submodules |
104+
| `-DWITH_DOC_MAN=OFF` | `ON` | Skip man page generation (removes asciidoc/xmlto dependency) |
105+
| `-DBUILD_TESTING=OFF` | `ON` | Disable unit tests |
106+
| `-DENABLE_CONNMARKTOS=ON` | `OFF` | Linux netfilter conntrack QoS support |
107+
| `-DENABLE_NFTABLES=ON` | `OFF` | nftables firewall integration |
108+
109+
On macOS, if libraries are installed via Homebrew, specify paths:
110+
111+
```bash
112+
cmake .. -DCMAKE_PREFIX_PATH="/usr/local/opt/mbedtls;/usr/local/opt/libsodium"
113+
```
84114

85115
### Debian & Ubuntu
86116

@@ -98,11 +128,6 @@ sudo apt install shadowsocks-libev
98128

99129
#### Build deb package from source
100130

101-
Supported distributions:
102-
103-
* Debian 8, 9 or higher
104-
* Ubuntu 14.04 LTS, 16.04 LTS, 16.10 or higher
105-
106131
You can build shadowsocks-libev and all its dependencies by script:
107132

108133
```bash
@@ -115,39 +140,6 @@ cd ~/build-area
115140
For older systems, building `.deb` packages is not supported.
116141
Please try to build and install directly from source. See the [Linux](#linux) section below.
117142

118-
**Note for Debian 8 (Jessie) users to build their own deb packages**:
119-
120-
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.
121-
122-
For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
123-
124-
``` bash
125-
cd shadowsocks-libev
126-
sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list'
127-
sudo sh -c 'printf "deb http://deb.debian.org/debian jessie-backports-sloppy main" >> /etc/apt/sources.list.d/jessie-backports.list'
128-
sudo apt-get install --no-install-recommends devscripts equivs
129-
mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
130-
./autogen.sh && dpkg-buildpackage -b -us -uc
131-
cd ..
132-
sudo dpkg -i shadowsocks-libev*.deb
133-
```
134-
135-
**Note for Debian 9 (Stretch) users to build their own deb packages**:
136-
137-
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.
138-
139-
For more info about backports, you can refer [Debian Backports](https://backports.debian.org).
140-
141-
``` bash
142-
cd shadowsocks-libev
143-
sudo sh -c 'printf "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-backports.list'
144-
sudo apt-get install --no-install-recommends devscripts equivs
145-
mk-build-deps --root-cmd sudo --install --tool "apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y"
146-
./autogen.sh && dpkg-buildpackage -b -us -uc
147-
cd ..
148-
sudo dpkg -i shadowsocks-libev*.deb
149-
```
150-
151143
#### Configure and start the service
152144

153145
```
@@ -214,60 +206,35 @@ In general, you need the following build dependencies:
214206
* asciidoc (for documentation only)
215207
* xmlto (for documentation only)
216208

217-
Notes: Fedora 26 libsodium version >= 1.0.12, so you can install via dnf install libsodium instead build from source.
209+
If your system is too old to provide libmbedtls and libsodium (>= 1.0.4), you will need to either install those libraries manually or upgrade your system.
218210

219-
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.
211+
Install build dependencies for your distribution:
220212

221-
If your system provides with those libraries, you **should not** install them from source. You should jump to this section and install them from the distribution repository instead.
213+
```bash
214+
# Debian / Ubuntu
215+
sudo apt-get install --no-install-recommends build-essential cmake pkg-config \
216+
libpcre2-dev libev-dev libc-ares-dev libmbedtls-dev libsodium-dev \
217+
asciidoc xmlto
218+
219+
# CentOS / Fedora / RHEL
220+
sudo yum install gcc cmake make pkg-config pcre2-devel c-ares-devel \
221+
libev-devel libsodium-devel mbedtls-devel asciidoc xmlto
222+
223+
# Arch
224+
sudo pacman -S gcc cmake make pkg-config pcre2 c-ares libev libsodium mbedtls \
225+
asciidoc xmlto
226+
```
222227

223-
For some of the distributions, you might install build dependencies like this:
228+
Then build and install:
224229

225230
```bash
226-
# Installation of basic build dependencies
227-
## Debian / Ubuntu
228-
sudo apt-get install --no-install-recommends build-essential cmake libpcre2-dev asciidoc xmlto libev-dev libc-ares-dev libmbedtls-dev libsodium-dev pkg-config
229-
## CentOS / Fedora / RHEL
230-
sudo yum install gcc cmake make asciidoc xmlto c-ares-devel libev-devel
231-
## Arch
232-
sudo pacman -S gcc cmake make asciidoc xmlto c-ares libev
233-
234-
# Installation of libsodium
235-
export LIBSODIUM_VER=1.0.16
236-
wget https://download.libsodium.org/libsodium/releases/old/libsodium-$LIBSODIUM_VER.tar.gz
237-
tar xvf libsodium-$LIBSODIUM_VER.tar.gz
238-
pushd libsodium-$LIBSODIUM_VER
239-
./configure --prefix=/usr && make
240-
sudo make install
241-
popd
242-
sudo ldconfig
243-
244-
# Installation of MbedTLS
245-
export MBEDTLS_VER=2.6.0
246-
wget https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls-$MBEDTLS_VER.tar.gz
247-
tar xvf mbedtls-$MBEDTLS_VER.tar.gz
248-
pushd mbedtls-$MBEDTLS_VER
249-
make SHARED=1 CFLAGS="-O2 -fPIC"
250-
sudo make DESTDIR=/usr install
251-
popd
252-
sudo ldconfig
253-
254-
# Start building
255231
git submodule update --init --recursive
256232
mkdir -p build && cd build
257233
cmake ..
258234
make
259235
sudo make install
260236
```
261237

262-
To run unit tests:
263-
264-
```bash
265-
cd build
266-
ctest --output-on-failure
267-
```
268-
269-
You may need to manually install missing softwares.
270-
271238
### FreeBSD
272239
#### Install
273240
Shadowsocks-libev is available in FreeBSD Ports Collection. You can install it in either way, `pkg` or `ports`.
@@ -460,10 +427,170 @@ you may refer to the man pages of the applications, respectively.
460427

461428
[-v] Verbose mode.
462429

463-
## Transparent proxy
430+
## Helper Scripts
431+
432+
### ss-setup
433+
434+
`ss-setup` is an interactive TUI (text user interface) tool for setting up shadowsocks-libev server and client configurations. It uses `whiptail` or `dialog` for the menu interface.
435+
436+
It is installed automatically by `make install` and can also be run directly from `scripts/ss-setup.sh`.
437+
438+
**Prerequisites:** `whiptail` or `dialog`, `openssl` (optional, for password generation)
439+
440+
#### Server setup (with systemd service)
441+
442+
Run as root for full functionality (config + systemd service installation):
443+
444+
```bash
445+
sudo ss-setup
446+
```
447+
448+
This launches an interactive menu that walks you through:
449+
1. Choosing a config instance name
450+
2. Setting the listen address and port (manual or random high port)
451+
3. Selecting an AEAD cipher (chacha20-ietf-poly1305, aes-256-gcm, etc.)
452+
4. Generating or entering a password
453+
5. Configuring timeout, network mode (TCP/UDP), and TCP Fast Open
454+
6. Optionally selecting a SIP003 plugin
455+
7. Installing and starting a systemd service
456+
457+
The config is saved to `/etc/shadowsocks-libev/<name>.json` and a systemd template service `shadowsocks-libev-server@<name>.service` is created.
458+
459+
At the end, it displays a `ss://` URI you can import into clients.
460+
461+
#### Client config generation
462+
463+
Select "Generate ss-local client config" from the main menu. The wizard prompts for the remote server address, port, cipher, password, and local SOCKS5 port, then writes a JSON config:
464+
465+
```bash
466+
# Run without root to generate config in the current directory
467+
ss-setup
468+
# Select: client -> fill in server details -> save
469+
470+
# Then start the client
471+
ss-local -c ~/ss-client.json
472+
```
473+
474+
#### Config-only mode (non-root)
475+
476+
When run without root, `ss-setup` skips service installation and plugin management, but still generates config files in the current directory:
477+
478+
```bash
479+
ss-setup
480+
# Config saved to ./config.json (in current directory)
481+
# Start manually:
482+
ss-server -c ./config.json
483+
```
484+
485+
#### Service management
486+
487+
From the main menu, select "Manage running services" to start, stop, restart, enable/disable, or view logs for any configured instance:
488+
489+
```
490+
sudo ss-setup
491+
# Select: service -> pick instance -> start/stop/restart/logs
492+
```
493+
494+
#### Plugin installation
495+
496+
Select "Install a SIP003 plugin" from the main menu (requires root). Supports automatic download of:
497+
- simple-obfs (build from source or package manager)
498+
- v2ray-plugin (GitHub release)
499+
- xray-plugin (GitHub release)
500+
- kcptun (GitHub release)
501+
- Custom plugin binary
502+
503+
### ss-nat
504+
505+
`ss-nat` is a helper script that sets up iptables NAT rules for `ss-redir` to provide transparent TCP/UDP redirection. It is installed on Linux systems by `make install`.
506+
507+
**Prerequisites:** Linux with `iptables`, `ipset`, and optionally TPROXY kernel module for UDP
508+
509+
#### Basic usage (TCP redirect)
510+
511+
```bash
512+
# Start ss-redir first
513+
ss-redir -s YOUR_SERVER_IP -p 8388 -l 1080 -k PASSWORD -m chacha20-ietf-poly1305 -u
514+
515+
# Set up NAT rules to redirect TCP traffic through ss-redir
516+
sudo ss-nat -s YOUR_SERVER_IP -l 1080
517+
```
518+
519+
#### Enable UDP relay with TPROXY
520+
521+
```bash
522+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -u
523+
```
524+
525+
#### Apply rules to OUTPUT chain (proxy the local machine itself)
526+
527+
```bash
528+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -u -o
529+
```
530+
531+
#### Use separate TCP/UDP servers
532+
533+
```bash
534+
sudo ss-nat -s TCP_SERVER_IP -l 1080 -S UDP_SERVER_IP -L 1080 -U
535+
```
536+
537+
#### Bypass specific WAN IPs
538+
539+
```bash
540+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -b "1.2.3.4 5.6.7.8"
541+
```
542+
543+
#### Use a bypass IP list file
544+
545+
```bash
546+
# Create a file with one IP/CIDR per line
547+
echo "1.2.3.0/24" > /etc/ss-bypass.list
548+
echo "5.6.7.0/24" >> /etc/ss-bypass.list
549+
550+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -i /etc/ss-bypass.list
551+
```
552+
553+
#### LAN access control
554+
555+
```bash
556+
# Whitelist mode: only proxy traffic from these LAN IPs
557+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -a "w192.168.1.10 192.168.1.20"
558+
559+
# Blacklist mode: proxy all LAN traffic except these IPs
560+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -a "b192.168.1.100"
561+
```
562+
563+
#### Flush all rules
564+
565+
```bash
566+
sudo ss-nat -f
567+
```
568+
569+
#### Complete example: transparent proxy gateway
570+
571+
Set up a Linux box as a transparent proxy gateway for the entire LAN:
572+
573+
```bash
574+
# 1. Start ss-redir with UDP relay
575+
ss-redir -s YOUR_SERVER_IP -p 8388 -l 1080 -k PASSWORD \
576+
-m chacha20-ietf-poly1305 -u -f /var/run/ss-redir.pid
577+
578+
# 2. Set up NAT rules (TCP + UDP, apply to local OUTPUT too)
579+
sudo ss-nat -s YOUR_SERVER_IP -l 1080 -u -o -I eth0
580+
581+
# 3. Point other devices' default gateway to this machine's LAN IP
582+
# and set their DNS to a public resolver (e.g., 1.1.1.1 or 8.8.8.8)
583+
584+
# To tear down:
585+
sudo ss-nat -f
586+
```
587+
588+
## Transparent proxy (manual iptables)
464589

465590
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.
466591

592+
Note: For most use cases, [`ss-nat`](#ss-nat) above is simpler than writing iptables rules manually.
593+
467594
# Create new chain
468595
iptables -t nat -N SHADOWSOCKS
469596
iptables -t mangle -N SHADOWSOCKS

0 commit comments

Comments
 (0)