Shadowsocks-libev
简介
Shadowsocks-Libev是一种轻巧的固定袜子5代理,用于嵌入式设备和低端盒子。
它是@clowwindy创建的阴影端口,由@madeye和@linusyang维护。
当前版本:3.3.5 | ChangElog
特征
Shadowsocks-libev用纯C编写,取决于libev。它旨在使Shadowsocks协议的轻量级实现,以使资源使用尽可能低。
有关Shadowsocks不同版本的功能比较的完整列表,请参阅Wiki页面。
快速开始
SNAP是安装最新二进制文件的推荐方法。
安装Snap Core
从snapcraft.io安装
稳定频道:
sudo snap install shadowsocks-libev
边缘通道:
sudo snap install shadowsocks-libev --edge
安装
特定于分布的指南
- Debian&Ubuntu
- 从存储库安装
- 从来源构建DEB软件包
- 配置并开始服务
- Fedora&Rhel
- 从Centos来源构建
- Archlinux&Manjaro
- 尼克斯
- 尼克斯
- 直接在类似Unix的系统上构建和安装
- freebsd
- 安装
- 配置
- 跑步
- 作为客户端运行
- OpenWrt
- OS X
- Windows(mingw)
- Docker
初始化构建环境
该存储库使用子模块,因此您应该在开始之前将其拉动,使用:
git submodule update --init --recursive
前构建配置指南
对于可用配置时间选项的完整列表,请尝试configure --help 。
Debian&Ubuntu
从存储库安装(不建议)
Shadowsocks-libev在官方存储库中可用于以下分布:
- Debian 8或更高版本,包括Oldoldstable(Jessie),旧马stable(拉伸),稳定(Buster),测试(Bullseye)和不稳定(SID)
- Ubuntu 16.10或更高
sudo apt update sudo apt install shadowsocks-libev
从来源构建DEB软件包
支持的分布:
- Debian 8、9或更高
- Ubuntu 14.04 LTS,16.04 LTS,16.10或更高
您可以通过脚本来构建Shadowsocks-libev及其所有依赖关系:
mkdir -p ~ /build-area/ cp ./scripts/build_deb.sh ~ /build-area/ cd ~ /build-area ./build_deb.sh
对于较旧的系统,不支持构建.deb软件包。请尝试直接从源构建和安装。请参阅下面的Linux部分。
注意Debian 8(Jessie)用户构建自己的DEB软件包:
我们强烈鼓励您从jessie-backports-sloppy安装Shadowsocks-Libev。如果您坚持从源头构建,则需要从jessie-backports-sloppy ,而不是主存储库中的Libsodium手动安装libsodium。
有关Backports的更多信息,您可以参考Debian Backports。
cd shadowsocks-libev sudo sh -c \' printf \"deb http://deb.**d*ebian.org/debian jessie-backports main\" > /etc/apt/sources.list.d/jessie-backports.list \' sudo sh -c \' printf \"deb http://deb.**d*ebian.org/debian jessie-backports-sloppy main\" >> /etc/apt/sources.list.d/jessie-backports.list \' sudo apt-get install --no-install-recommends devscripts equivs mk-build-deps --root-cmd sudo --install --tool \" apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \" ./autogen.sh && dpkg-buildpackage -b -us -uc cd .. sudo dpkg -i shadowsocks-libev * .deb
请注意Debian 9(strawt)用户构建自己的DEB软件包:
我们强烈鼓励您从stretch-backports中安装Shadowsocks-Libev。如果您坚持从源头构建,则需要手动从stretch-backports中安装libsodium,而不是主存储库中的libsodium。
有关Backports的更多信息,您可以参考Debian Backports。
cd shadowsocks-libev sudo sh -c \' printf \"deb http://deb.**d*ebian.org/debian stretch-backports main\" > /etc/apt/sources.list.d/stretch-backports.list \' sudo apt-get install --no-install-recommends devscripts equivs mk-build-deps --root-cmd sudo --install --tool \" apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \" ./autogen.sh && dpkg-buildpackage -b -us -uc cd .. sudo dpkg -i shadowsocks-libev * .deb
配置并开始服务
# Edit the configuration file
sudo vim /etc/shadowsocks-libev/config.json
# Edit the default configuration for debian
sudo vim /etc/default/shadowsocks-libev
# Start the service
sudo /etc/init.d/shadowsocks-libev start # for sysvinit, or
sudo systemctl start shadowsocks-libev # for systemd
Fedora&Rhel
支持的分布:
- 最近的Fedora版本(直到EOL)
- RHEL 6、7和衍生物(包括CentOS,科学Linux)
从Centos来源构建
如果您使用的是CentOS 7,则需要安装这些预定量以从源代码构建:
yum install epel-release -y yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
Archlinux&Manjaro
sudo pacman -S shadowsocks-libev
请参阅下游PKGBUILD脚本以获取额外的修改和特定于分布的错误。
尼克斯
nix-env -iA nixos.shadowsocks-libev
尼克斯
nix-env -iA nixpkgs.shadowsocks-libev
Linux
通常,您需要以下构建依赖性:
- Autotools(AutoConf,Automake,Libtool)
- getText
- pkg-config
- libmbedtls
- libsodium
- libpcre3(旧pcre库)
- libev
- libc-ares
- ASCIIDOC(仅用于文档)
- XMLTO(仅用于文档)
注意:Fedora 26 libsodium版本> = 1.0.12,因此您可以通过DNF安装libodium而不是从源构建。
如果您的系统太老了,无法提供libmbedtls和libsodium(晚于v1.0.8 ),则需要手动安装这些库或升级系统。
如果您的系统与这些库一起提供,则不应从源中安装它们。您应该跳到本节并从分发存储库中安装它们。
对于某些分布,您可能会安装这样的构建依赖项:
# Installation of basic build dependencies # # Debian / Ubuntu 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 pkg-config # # CentOS / Fedora / RHEL sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto c-ares-devel libev-devel # # Arch sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto c-ares libev # Installation of libsodium export LIBSODIUM_VER=1.0.16 wget https://download.lib*so**dium.org/libsodium/releases/old/libsodium- $LIBSODIUM_VER .tar.gz tar xvf libsodium- $LIBSODIUM_VER .tar.gz pushd libsodium- $LIBSODIUM_VER ./configure --prefix=/usr && make sudo make install popd sudo ldconfig # Installation of MbedTLS export MBEDTLS_VER=2.6.0 wget https://g*ithub.co**m/Mbed-TLS/mbedtls/archive/refs/tags/mbedtls- $MBEDTLS_VER .tar.gz tar xvf mbedtls- $MBEDTLS_VER .tar.gz pushd mbedtls- $MBEDTLS_VER make SHARED=1 CFLAGS= \" -O2 -fPIC \" sudo make DESTDIR=/usr install popd sudo ldconfig # Start building ./autogen.sh && ./configure && make sudo make install
您可能需要手动安装缺失的软件。
freebsd
安装
Shadowsocks-libev可在FreeBSD端口集合中找到。您可以以任何方式安装pkg或ports 。
PKG(推荐)
pkg install shadowsocks-libev
端口
cd /usr/ports/net/shadowsocks-libev
make install
配置
编辑您的config.json文件。默认情况下,它位于/usr/local/etc/shadowsocks-libev中。
要启用shadowsocks-libev,请将以下RC变量添加到您的/etc/rc.conf文件:
shadowsocks_libev_enable=\"YES\"
跑步
启动ShadowWowsocks服务器:
service shadowsocks_libev start
作为客户端运行
默认情况下,shadowsocks-libev在freebsd中以服务器运行。如果您想在客户端模式下启动shadowsocks-libev,则可以手动修改RC脚本( /usr/local/etc/rc.d/shadowsocks_libev )。
# modify the following line from \"ss-server\" to \"ss-local\"
command=\"/usr/local/bin/ss-local\"
请注意,这只是一个解决方法,每次您升级端口时,更改都会被新版本覆盖。
OpenWrt
OpenWRT项目在此处维护:OpenWrt-Shadowsocks。
OS X
对于OS X,请使用Homebrew安装或构建。
安装自制:
ruby -e \" $( curl -fsSL https://raw.*githubuser*conten*t.com/Homebrew/install/master/install ) \"
安装Shadowsocks-libev:
brew install shadowsocks-libev
Windows(mingw)
要构建Windows本地二进制文件,推荐的方法是使用Docker:
-
在Windows上:
docker\\mingw中的双击make.bat -
在类似Unix的系统上:
cd shadowsocks-libev/docker/mingw make
同一目录将生成具有32位和64位二进制文件的Tarball。
您也可以手动使用mingw-w64编译器以unix状的外壳(msys2/cygwin)构建,也可以在类似Unix的系统(Linux/MacOS)上进行交叉编译。请参阅docker/mingw中的构建脚本。
当前,您需要使用修补的LIBEV库进行mingw:
- https://gi*thub.*c*om/shadowsocks/libev/archive/mingw.zip
请注意,TCP快速打开(TFO)仅在Windows 10、1607或更高版本上可用(正是构建> = 14393)。如果您使用的是1709 (构建16299)或更高版本,则还需要在PowerShell/命令提示中以管理员的身份运行以下命令,然后重新启动以正确使用TFO:
netsh int tcp set global fastopenfallback=disabled
Docker
如您所料,只需拉动图像并运行即可。
docker pull shadowsocks/shadowsocks-libev
docker run -e PASSWORD=<password> -p<server-port>:8388 -p<server-port>:8388/udp -d shadowsocks/shadowsocks-libev
有关图像的更多信息,请参见此处。
用法
对于所有受支持的参数的详细列表,您可以分别参考应用程序的人页面。
ss-[local|redir|server|tunnel|manager]
-s <server_host> Host name or IP address of your remote server.
-p <server_port> Port number of your remote server.
-l <local_port> Port number of your local server.
-k <password> Password of your remote server.
-m <encrypt_method> Encrypt method: rc4-md5,
aes-128-gcm, aes-192-gcm, aes-256-gcm,
aes-128-cfb, aes-192-cfb, aes-256-cfb,
aes-128-ctr, aes-192-ctr, aes-256-ctr,
camellia-128-cfb, camellia-192-cfb,
camellia-256-cfb, bf-cfb,
chacha20-ietf-poly1305,
xchacha20-ietf-poly1305,
salsa20, chacha20 and chacha20-ietf.
The default cipher is chacha20-ietf-poly1305.
[-a <user>] Run as another user.
[-f <pid_file>] The file path to store pid.
[-t <timeout>] Socket timeout in seconds.
[-c <config_file>] The path to config file.
[-n <number>] Max number of open files.
[-i <interface>] Network interface to bind.
(not available in redir mode)
[-b <local_address>] Local address to bind.
For servers: Specify the local address to use
while this server is making outbound
connections to remote servers on behalf of the
clients.
For clients: Specify the local address to use
while this client is making outbound
connections to the server.
[-u] Enable UDP relay.
(TPROXY is required in redir mode)
[-U] Enable UDP relay and disable TCP relay.
(not available in local mode)
[-T] Use tproxy instead of redirect. (for tcp)
(only available in redir mode)
[-L <addr>:<port>] Destination server address and port
for local port forwarding.
(only available in tunnel mode)
[-6] Resolve hostname to IPv6 address first.
[-d <addr>] Name servers for internal DNS resolver.
(only available in server mode)
[--reuse-port] Enable port reuse.
[--fast-open] Enable TCP fast open.
with Linux kernel > 3.7.0.
(only available in local and server mode)
[--acl <acl_file>] Path to ACL (Access Control List).
(only available in local and server mode)
[--manager-address <addr>] UNIX domain socket address.
(only available in server and manager mode)
[--mtu <MTU>] MTU of your network interface.
[--mptcp] Enable Multipath TCP on MPTCP Kernel.
[--no-delay] Enable TCP_NODELAY.
[--executable <path>] Path to the executable of ss-server.
(only available in manager mode)
[-D <path>] Path to the working directory of ss-manager.
(only available in manager mode)
[--key <key_in_base64>] Key of your remote server.
[--plugin <name>] Enable SIP003 plugin. (Experimental)
[--plugin-opts <options>] Set SIP003 plugin options. (Experimental)
[-v] Verbose mode.
透明代理
最新的Shadowsocks-Libev提供了Redir模式。您可以配置基于Linux的框或路由器以透明地代理所有TCP流量,如果使用OpenWrt-Power Router,这很方便。
# Create new chain
iptables -t nat -N SHADOWSOCKS
iptables -t mangle -N SHADOWSOCKS
# Ignore your shadowsocks server\'s addresses
# It\'s very IMPORTANT, just be careful.
iptables -t nat -A SHADOWSOCKS -d 123.123.123.123 -j RETURN
# Ignore LANs and any other addresses you\'d like to bypass the proxy
# See Wikipedia and RFC5735 for full list of reserved networks.
# See ashi009/bestroutetb for a highly optimized CHN route list.
iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN
# Anything else should be redirected to shadowsocks\'s local port
iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345
# Add any UDP rules
ip route add local default dev lo table 100
ip rule add fwmark 1 lookup 100
iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
# Apply the rules
iptables -t nat -A PREROUTING -p tcp -j SHADOWSOCKS
iptables -t mangle -A PREROUTING -j SHADOWSOCKS
# Start the shadowsocks-redir
ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid
透明代理(纯Tproxy)
在Linux主机上执行此脚本可以代理该计算机的所有传出流量(除了发送到保留地址的流量)。同一LAN下的其他主机还可以将其默认网关更改为该Linux主机的IP(同时将DNS服务器更改为1.1.1.1或8.8.8.8等),以代理其传出流量。
当然,IPv6代理是相似的,只需将
iptables更改为ip6tables,ip到ip -6127.0.0.1::1和其他详细信息。
#! /bin/bash start_ssredir () { # please modify MyIP, MyPort, etc. (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 & ) } stop_ssredir () { kill -9 $( pidof ss-redir ) & > /dev/null } start_iptables () { # #################### SSREDIR ##################### iptables -t mangle -N SSREDIR # connection-mark -> packet-mark iptables -t mangle -A SSREDIR -j CONNMARK --restore-mark iptables -t mangle -A SSREDIR -m mark --mark 0x2333 -j RETURN # please modify MyIP, MyPort, etc. # ignore traffic sent to ss-server iptables -t mangle -A SSREDIR -p tcp -d MyIP --dport MyPort -j RETURN iptables -t mangle -A SSREDIR -p udp -d MyIP --dport MyPort -j RETURN # ignore traffic sent to reserved addresses iptables -t mangle -A SSREDIR -d 0.0.0.0/8 -j RETURN iptables -t mangle -A SSREDIR -d 10.0.0.0/8 -j RETURN iptables -t mangle -A SSREDIR -d 100.64.0.0/10 -j RETURN iptables -t mangle -A SSREDIR -d 127.0.0.0/8 -j RETURN iptables -t mangle -A SSREDIR -d 169.254.0.0/16 -j RETURN iptables -t mangle -A SSREDIR -d 172.16.0.0/12 -j RETURN iptables -t mangle -A SSREDIR -d 192.0.0.0/24 -j RETURN iptables -t mangle -A SSREDIR -d 192.0.2.0/24 -j RETURN iptables -t mangle -A SSREDIR -d 192.88.99.0/24 -j RETURN iptables -t mangle -A SSREDIR -d 192.168.0.0/16 -j RETURN iptables -t mangle -A SSREDIR -d 198.18.0.0/15 -j RETURN iptables -t mangle -A SSREDIR -d 198.51.100.0/24 -j RETURN iptables -t mangle -A SSREDIR -d 203.0.113.0/24 -j RETURN iptables -t mangle -A SSREDIR -d 224.0.0.0/4 -j RETURN iptables -t mangle -A SSREDIR -d 240.0.0.0/4 -j RETURN iptables -t mangle -A SSREDIR -d 255.255.255.255/32 -j RETURN # mark the first packet of the connection iptables -t mangle -A SSREDIR -p tcp --syn -j MARK --set-mark 0x2333 iptables -t mangle -A SSREDIR -p udp -m conntrack --ctstate NEW -j MARK --set-mark 0x2333 # packet-mark -> connection-mark iptables -t mangle -A SSREDIR -j CONNMARK --save-mark # #################### OUTPUT ##################### # proxy the outgoing traffic from this machine iptables -t mangle -A OUTPUT -p tcp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR iptables -t mangle -A OUTPUT -p udp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR # #################### PREROUTING ##################### # proxy traffic passing through this machine (other->other) iptables -t mangle -A PREROUTING -p tcp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR iptables -t mangle -A PREROUTING -p udp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR # hand over the marked package to TPROXY for processing iptables -t mangle -A PREROUTING -p tcp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 iptables -t mangle -A PREROUTING -p udp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 } stop_iptables () { # #################### PREROUTING ##################### iptables -t mangle -D PREROUTING -p tcp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 & > /dev/null iptables -t mangle -D PREROUTING -p udp -m mark --mark 0x2333 -j TPROXY --on-ip 127.0.0.1 --on-port 60080 & > /dev/null iptables -t mangle -D PREROUTING -p tcp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR & > /dev/null iptables -t mangle -D PREROUTING -p udp -m addrtype ! --src-type LOCAL ! --dst-type LOCAL -j SSREDIR & > /dev/null # #################### OUTPUT ##################### iptables -t mangle -D OUTPUT -p tcp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR & > /dev/null iptables -t mangle -D OUTPUT -p udp -m addrtype --src-type LOCAL ! --dst-type LOCAL -j SSREDIR & > /dev/null # #################### SSREDIR ##################### iptables -t mangle -F SSREDIR & > /dev/null iptables -t mangle -X SSREDIR & > /dev/null } start_iproute2 () { ip route add local default dev lo table 100 ip rule add fwmark 0x2333 table 100 } stop_iproute2 () { ip rule del table 100 & > /dev/null ip route flush table 100 & > /dev/null } start_resolvconf () { # or nameserver 8.8.8.8, etc. echo \" nameserver 1.1.1.1 \" > /etc/resolv.conf } stop_resolvconf () { echo \" nameserver 114.114.114.114 \" > /etc/resolv.conf } start () { echo \" start ... \" start_ssredir start_iptables start_iproute2 start_resolvconf echo \" start end \" } stop () { echo \" stop ... \" stop_resolvconf stop_iproute2 stop_iptables stop_ssredir echo \" stop end \" } restart () { stop sleep 1 start } main () { if [ $# -eq 0 ] ; then echo \" usage: $0 start|stop|restart ... \" return 1 fi for funcname in \" $@ \" ; do if [ \" $( type -t $funcname ) \" != \' function \' ] ; then echo \" \' $funcname \' not a shell function \" return 1 fi done for funcname in \" $@ \" ; do $funcname done return 0 } main \" $@ \"
安全提示
对于任何公共服务器,要避免访问服务器本地主机的用户,请在命令行中添加--acl acl/server_block_local.acl 。
尽管Shadowsocks-Libev可以很好地处理数千个并发连接,但我们仍然建议设置服务器的防火墙规则以限制每个用户的连接:
# Up to 32 connections are enough for normal usage
iptables -A INPUT -p tcp --syn --dport ${SHADOWSOCKS_PORT} -m connlimit --connlimit-above 32 -j REJECT --reject-with tcp-reset
执照
Copyright: 2013-2015, Clow Windy <clowwindy42@gmail.com>
2013-2018, Max Lv <max.c.lv@gmail.com>
2014, Linus Yang <linusyang@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.*g*n*u.org/licenses/>.
