This is a port of shadowsocks.
shadowsocks is a fast tunnel proxy that helps you bypass firewalls.
Library | Description |
---|---|
shadowsocks | shadowsocks core protocol |
shadowsocks-service | Services for serving shadowsocks |
shadowsocks-rust | Binaries running common shadowsocks services |
Related Projects:
sslocal
using GTK, discussionsslocal
, discussionhickory-dns
- Uses hickory-resolver
as DNS resolver instead of tokio
's builtin.
local-http
- Allow using HTTP protocol for sslocal
local-http-native-tls
- Support HTTPS with native-tls
local-http-rustls
- Support HTTPS with rustls
local-tunnel
- Allow using tunnel protocol for sslocal
local-socks4
- Allow using SOCKS4/4a protocol for sslocal
local-redir
- Allow using redir (transparent proxy) protocol for sslocal
local-dns
- Allow using dns protocol for sslocal
, serves as a DNS server proxying queries to local or remote DNS servers by ACL rules
local-fake-dns
- FakeDNS, allocating an IP address for each individual Query from a specific IP pool
local-tun
- TUN interface support for sslocal
local-online-config
- SIP008 Online Configuration Delivery
stream-cipher
- Enable deprecated stream ciphers. WARN: stream ciphers are UNSAFE!
aead-cipher-extra
- Enable non-standard AEAD ciphers
aead-cipher-2022
- Enable AEAD-2022 ciphers (SIP022)
aead-cipher-2022-extra
- Enable AEAD-2022 extra ciphers (non-standard ciphers)
This project uses system (libc) memory allocator (Rust's default). But it also allows you to use other famous allocators by features:
jemalloc
- Uses jemalloc as global memory allocatormimalloc
- Uses mi-malloc as global memory allocatortcmalloc
- Uses TCMalloc as global memory allocator. It tries to link system-wide tcmalloc by default, use vendored from source with tcmalloc-vendored
.snmalloc
- Uses snmalloc as global memory allocatorrpmalloc
- Uses rpmalloc as global memory allocatorInstall from crates.io:
# Install from crates.io
cargo install shadowsocks-rust
then you can find sslocal
and ssserver
in $CARGO_HOME/bin
.
For macOS and Linux, you can install it using Homebrew:
brew install shadowsocks-rust
# Install from snapstore
snap install shadowsocks-rust
# List services
snap services shadowsocks-rust
# Enable and start shadowsocks-rust.sslocal-daemon snap service
snap start --enable shadowsocks-rust.sslocal-daemon
# Show generated systemd service status
systemctl status snap.shadowsocks-rust.sslocal-daemon.service
# Override generated systemd service (configure startup options)
systemctl edit snap.shadowsocks-rust.sslocal-daemon.service
## NOTE: you can pass args to sslocal:
## [Service]
## ExecStart=
## ExecStart=/usr/bin/snap run shadowsocks-rust.sslocal-daemon -b "127.0.0.1:1080" --server-url "ss://...."
# Restart generated systemd service to apply changes
systemctl restart snap.shadowsocks-rust.sslocal-daemon.service
# ... and show service status
systemctl status snap.shadowsocks-rust.sslocal-daemon.service
Download static-linked build here.
build-windows
: Build for x86_64-pc-windows-msvc
build-linux
: Build for x86_64-unknown-linux-gnu
, Debian 9 (Stretch), GLIBC 2.18build-docker
: Build for x86_64-unknown-linux-musl
, x86_64-pc-windows-gnu
, ... (statically linked)This project provided Docker images for the linux/i386
and linux/amd64
and linux/arm64/v8
architectures.
⚠️ Docker containers do not have access to IPv6 by default: Make sure to disable IPv6 Route in the client or enable IPv6 access to docker containers.
Docker will pull the image of the appropriate architecture from our GitHub Packages.
docker pull ghcr.io/shadowsocks/sslocal-rust:latest
docker pull ghcr.io/shadowsocks/ssserver-rust:latest
If you want to build the Docker image yourself, you need to use the BuildX.
docker buildx build -t shadowsocks/ssserver-rust:latest -t shadowsocks/ssserver-rust:v1.15.2 --target ssserver .
docker buildx build -t shadowsocks/sslocal-rust:latest -t shadowsocks/sslocal-rust:v1.15.2 --target sslocal .
You need to mount the configuration file into the container and create an external port map for the container to connect to it.
docker run --name sslocal-rust
--restart always
-p 1080:1080/tcp
-v /path/to/config.json:/etc/shadowsocks-rust/config.json
-dit ghcr.io/shadowsocks/sslocal-rust:latest
docker run --name ssserver-rust
--restart always
-p 8388:8388/tcp
-p 8388:8388/udp
-v /path/to/config.json:/etc/shadowsocks-rust/config.json
-dit ghcr.io/shadowsocks/ssserver-rust:latest
This project provided yaml manifests for deploying to Kubernetes.
You can leverage k8s Service to expose traffic outside, like LoadBalancer or NodePort which gains more fine-grained compared with fixed host or port.
For a more interesting use case, you can use a Ingress(Istio, nginx, etc.) which routes the matched traffic to shadowsocks along with the real web service.
kubectl
kubectl apply -f https://github.com/shadowsocks/shadowsocks-rust/raw/master/k8s/shadowsocks-rust.yaml
You can change the config via editing the ConfigMap named shadowsocks-rust
.
For more fine-grained control, use helm
.
helm
helm install my-release k8s/chart -f my-values.yaml
Below is the common default values you can change:
# This is the shadowsocks config which will be mount to /etc/shadowocks-rust.
# You can put arbitrary yaml here, and it will be translated to json before mounting.
servers:
- server: "::"
server_port: 8388
service_port: 80 # the k8s service port, default to server_port
password: mypassword
method: aes-256-gcm
fast_open: true
mode: tcp_and_udp
# plugin: v2ray-plugin
# plugin_opts: server;tls;host=github.com
# Whether to download v2ray and xray plugin.
downloadPlugins: false
# Name of the ConfigMap with config.json configuration for shadowsocks-rust.
configMapName: ""
service:
# Change to LoadBalancer if you are behind a cloud provider like aws, gce, or tke.
type: ClusterIP
# Bind shadowsocks port port to host, i.e., we can use host:port to access shawdowsocks server.
hostPort: false
replicaCount: 1
image:
repository: ghcr.io/shadowsocks/ssserver-rust
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
Use cargo to build. NOTE: RAM >= 2GiB
cargo build --release
Then sslocal
and ssserver
will appear in ./target/(debug|release)/
, it works similarly as the two binaries in the official ShadowSocks' implementation.
make install TARGET=release
Then sslocal
, ssserver
, ssmanager
and ssurl
will be installed to /usr/local/bin
(variable PREFIX).
For Windows users, if you have encountered any problem in building, check and discuss in #102.
If you are building for your current CPU platform (for example, build and run on your personal computer), it is recommended to set target-cpu=native
feature to let rustc
generate and optimize code for the CPU running the compiler.
export RUSTFLAGS="-C target-cpu=native"
Requirements:
./build/build-release
Then sslocal
, ssserver
, ssmanager
and ssurl
will be packaged in
./build/shadowsocks-${VERSION}-stable.x86_64-unknown-linux-musl.tar.xz
./build/shadowsocks-${VERSION}-stable.x86_64-pc-windows-gnu.zip
Read Cargo.toml
for more details.
Generate a safe and secured password for a specific encryption method (aes-128-gcm
in the example) with:
ssservice genkey -m "aes-128-gcm"
Create a ShadowSocks' configuration file. Example
{
"server": "my_server_ip",
"server_port": 8388,
"password": "rwQc8qPXVsRpGx3uW+Y3Lj4Y42yF9Bs0xg1pmx8/+bo=",
"method": "aes-256-gcm",
// ONLY FOR `sslocal`
// Delete these lines if you are running `ssserver` or `ssmanager`
"local_address": "127.0.0.1",
"local_port": 1080
}
Detailed explanation of the configuration file could be found in shadowsocks' documentation. (Link to original project, not maintained anymore !)
⚠️ For snap installations, configuration file is most probably located in/var/snap/shadowsocks-rust/common/etc/shadowsocks-rust/config.json
(see #621 / #1146)
In shadowsocks-rust, we also have an extended configuration file format, which is able to define more than one server. You can also disable individual servers.
{
"servers": [
{
"server": "127.0.0.1",
"server_port": 8388,
"password": "rwQc8qPXVsRpGx3uW+Y3Lj4Y42yF9Bs0xg1pmx8/+bo=",
"method": "aes-256-gcm",
"timeout": 7200
},
{
"server": "127.0.0.1",
"server_port": 8389,
"password": "/dliNXn5V4jg6vBW4MnC1I8Jljg9x7vSihmk6UZpRBM=",
"method": "chacha20-ietf-poly1305"
},
{
"disabled": true,
"server": "eg.disable.me",
"server_port": 8390,
"password": "mGvbWWay8ueP9IHnV5F1uWGN2BRToiVCAWJmWOTLU24=",
"method": "chacha20-ietf-poly1305"
}
],
// ONLY FOR `sslocal`
// Delete these lines if you are running `ssserver` or `ssmanager`
"local_port": 1080,
"local_address": "127.0.0.1"
}
sslocal
automatically selects the best server with the lowest latency and the highest availability.
Start Shadowsocks client and server with:
sslocal -c config.json
ssserver -c config.json
If you Build it with Cargo:
cargo run --bin sslocal -- -c config.json
cargo run --bin ssserver -- -c config.json
List all available arguments with -h
.
Start local client with configuration file
# Read local client configuration from file
sslocal -c /path/to/shadowsocks.json
# Pass all parameters via command line
sslocal -b "127.0.0.1:1080" -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "v2ray-plugin" --plugin-opts "server;tls;host=github.com"
# Pass server with SIP002 URL
sslocal -b "127.0.0.1:1080" --server-url "ss://[email protected]:8388/?plugin=v2ray-plugin%3Bserver%3Btls%3Bhost%3Dgithub.com"
sslocal -b "127.0.0.1:3128" --protocol http -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty"
All parameters are the same as Socks5 client, except --protocol http
.
# Set 127.0.0.1:8080 as the target for forwarding to
sslocal --protocol tunnel -b "127.0.0.1:3128" -f "127.0.0.1:8080" -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty"
--protocol tunnel
enables local client Tunnel mode-f "127.0.0.1:8080
sets the tunnel target addressNOTE: It currently only supports
iptables
targets REDIRECT
and TPROXY
)pf
), such as OS X 10.10+, FreeBSD, ...sslocal -b "127.0.0.1:60080" --protocol redir -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --tcp-redir "redirect" --udp-redir "tproxy"
Redirects connections with iptables
configurations to the port that sslocal
is listening on.
--protocol redir
enables local client Redir mode--tcp-redir
sets TCP mode to REDIRECT
(Linux)--udp-redir
sets UDP mode to TPROXY
(Linux)NOTE: It currently only supports
Create a Tun interface with name tun0
ip tuntap add mode tun tun0
ifconfig tun0 inet 10.255.0.1 netmask 255.255.255.0 up
Start sslocal
with --protocol tun
and binds to tun0
sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface lo0 --tun-interface-name tun0
sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface lo0 --tun-interface-address 10.255.0.1/24
It will create a Tun interface with address 10.255.0.1
and netmask 255.255.255.0
.
Download wintun.dll
from Wintun, and place it in the folder with shadowsocks' runnable binaries, or in the system PATH.
sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbound-bind-interface "Ethernet 0" --tun-interface-name "shadowsocks"
Compile it by enabling --features "winservice"
(not included in the default build):
cargo build --release --bin "sswinservice" --features "winservice"
Install it as a Windows Service (PowerShell):
New-Service -Name "shadowsocks-local-service" `
-DisplayName "Shadowsocks Local Service" `
-BinaryPathName "<Pathto>sswinservice.exe local -c <Pathto>local_config.json"
There are other ways to install sswinservice
as a Windows Service, for example, the sc
command.
As you may have noticed that the -BinaryPathName
contains not only just the sswinservice.exe
, but local -c local_config.json
. These command line parameters will be used as the default parameter when the Windows Service starts. You can also start the service with customized parameters.
Learn more from Microsoft's Document.
The sswinservice
's parameter works exactly the same as ssservice
. It supports local
, server
and manager
subcommands.
# Read server configuration from file
ssserver -c /path/to/shadowsocks.json
# Pass all parameters via command line
ssserver -s "[::]:8388" -m "aes-256-gcm" -k "hello-kitty" --plugin "v2ray-plugin" --plugin-opts "server;tls;host=github.com"
Supported Manage Multiple Users API:
add
- Starts a server instanceremove
- Deletes an existing server instancelist
- Lists all current running serversping
- Lists all servers' statistic dataNOTE: stat
command is not supported. Because servers are running in the same process with the manager itself.
# Start it just with --manager-address command line parameter
ssmanager --manager-address "127.0.0.1:6100"
# For *nix system, manager can bind to unix socket address
ssmanager --manager-address "/tmp/shadowsocks-manager.sock"
# You can also provide a configuration file
#
# `manager_address` key must be provided in the configuration file
ssmanager -c /path/to/shadowsocks.json
# Create one server by UDP
echo 'add: {"server_port":8388,"password":"hello-kitty"}' | nc -u '127.0.0.1' '6100'
# Close one server by unix socket
echo 'remove: {"server_port":8388}' | nc -Uu '/tmp/shadowsocks-manager.sock'
For manager UI, check more details in the shadowsocks-manager project.
Example configuration:
{
// Required option
// Address that ssmanager is listening on
"manager_address": "127.0.0.1",
"manager_port": 6100,
// Or bind to a Unix Domain Socket
"manager_address": "/tmp/shadowsocks-manager.sock",
"servers": [
// These servers will be started automatically when ssmanager is started
],
// Outbound socket binds to this IP address
// For choosing different network interface on the same machine
"local_address": "xxx.xxx.xxx.xxx",
// Other options that may be passed directly to new servers
}
{
// LOCAL: Listen address. This is exactly the same as `locals[0]`
// SERVER: Bind address for remote sockets, mostly used for choosing interface
// Don't set it if you don't know what's this for.
"local_address": "127.0.0.1",
"local_port": 1080,
// Extended multiple local configuration
"locals": [
{
// Basic configuration, a SOCKS5 local server
"local_address": "127.0.0.1",
"local_port": 1080,
// OPTIONAL. Setting the `mode` for this specific local server instance.
// If not set, it will derive from the outer `mode`
"mode": "tcp_and_udp",
// OPTIONAL. Authentication configuration file
// Configuration file document could be found in the next section.
"socks5_auth_config_path": "/path/to/auth.json",
// OPTIONAL. Instance specific ACL
"acl": "/path/to/acl/file.acl",
// OPTIONAL. macOS launchd activate socket
"launchd_tcp_socket_name": "TCPListener",
"launchd_udp_socket_name": "UDPListener"
},
{
// SOCKS5, SOCKS4/4a local server
"protocol": "socks",
// Listen address
"local_address": "127.0.0.1",
"local_port": 1081,
// OPTIONAL. Enables UDP relay
"mode": "tcp_and_udp",
// OPTIONAL. Customizing the UDP's binding address. Depending on `mode`, if
// - TCP is enabled, then SOCKS5's UDP Association command will return this address
// - UDP is enabled, then SOCKS5's UDP server will listen to this address.
"local_udp_address": "127.0.0.1",
"local_udp_port": 2081,
// OPTIONAL. macOS launchd activate socket
"launchd_tcp_socket_name": "TCPListener",
"launchd_udp_socket_name": "UDPListener"
},
{
// Tunnel local server (feature = "local-tunnel")
"protocol": "tunnel",
// Listen address
"local_address": "127.0.0.1",
"local_port": 5353,