Git Product home page Git Product logo

shadowsocks-libev's Introduction

shadowsocks-libev

Intro

Shadowsocks-libev is a lightweight secured SOCKS5 proxy for embedded devices and low-end boxes.

It is a port of Shadowsocks created by @clowwindy, and maintained by @madeye and @linusyang.

Current version: 3.0.8 | Changelog

Travis CI: Travis CI

Features

Shadowsocks-libev is written in pure C and depends on libev. It's designed to be a lightweight implementation of shadowsocks protocol, in order to keep the resource usage as low as possible.

For a full list of feature comparison between different versions of shadowsocks, refer to the Wiki page.

Prerequisites

Get the latest source code

To get the latest source code, you should also update the submodules as following:

git clone https://github.com/Windendless/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive

Build and install the latest mbedTLS

export MBEDTLS_VER=2.4.0
wget https://tls.mbed.org/download/mbedtls-$MBEDTLS_VER-gpl.tgz
tar xvf mbedtls-$MBEDTLS_VER-gpl.tgz
pushd mbedtls-$MBEDTLS_VER
make SHARED=1 CFLAGS=-fPIC
sudo make DESTDIR=/usr install
popd
sudo ldconfig

Installation

Distribution-specific guide


Pre-build configure guide

For a complete list of avaliable configure-time option, try configure --help.

Windows

Build from source with centos

If you are using CentOS 7, you need to install these prequirement to build from source code

yum install epel-release -y
yum install gcc gettext autoconf libtool automake make  -y
yum install mingw64-gcc mingw64-headers mingw64-winpthreads-static mingw64-binutils

rebuild mbedTLS

pushd mbedtls-2.3.0/
make clean
AR=x86_64-w64-mingw32-ar CC=x86_64-w64-mingw32-gcc WINDOWS_BUILD=1 make
WINDOWS_BUILD=1 make install DESTDIR="$HOME/prebuilt/mbedtls"
popd

download pcre source tarball to the home directory, and build it like this (may take a few minutes):

curl https://jaist.dl.sourceforge.NET/project/pcre/pcre/8.39/pcre-8.39.tar.gz | tar xvz
pushd pcre-8.39/
./configure --host=x86_64-w64-mingw32 --disable-cpp --disable-shared --prefix="$HOME/prebuilt/pcre"
make
make install
popd

Then, build the binary using the commands below, and all .exe files will be built at $HOME/dist-build/bin:

./autogen.sh
./configure --disable-documentation --host=x86_64-w64-mingw32 --prefix="$HOME/dist-build" --disable-ssp \
--with-mbedtls="$HOME/prebuilt/mbedtls" \
--with-pcre="$HOME/prebuilt/pcre"
make && make install

cd $HOME/dist-build/bin
cp /usr/x86_64-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll .

x86_64-w64-mingw32-strip ss-local.exe ss-tunnel.exe libwinpthread-1.dll

Debian & Ubuntu

Install from repository

Note: The repositories doesn't always contain the latest version. Please build from source if you want the latest version (see below)

Shadowsocks-libev is available in the official repository for Debian 9("Stretch"), unstable, Ubuntu 16.10 and later derivatives:

sudo apt update
sudo apt install shadowsocks-libev

For Debian Jessie users, please install it from jessie-backports:

sudo sh -c 'printf "deb http://httpredir.debian.org/debian jessie-backports main" > /etc/apt/sources.list.d/jessie-backports.list'
sudo apt update
sudo apt -t jessie-backports install shadowsocks-libev

Build deb package from source

Supported Platforms:

  • Debian 8 (see below), 9, unstable
  • Ubuntu 16.04 or higher

For older systems, building .deb packages is not supported. Please directly install from source. You may need to resolve library dependencies by yourself.

Note for Debian 8.x users: We strongly encourage you to install shadowsocks-libev from jessie-backports. Please follow instructions on Debian Backports.

If you insist on building from source, you will need to manually install libsodium from jessie-backports, NOT libsodium in main repository. Please follow the instructions on Debian Backports Website.

You can also use the same build script for Ubuntu LTS as below.

Note for Debian (>=8) / Ubuntu 14.04 (Trusty) / 16.04 (Xenial) users: You can build shadowsocks-libev and all its dependencies by script:

mkdir -p ~/build-area/
cp ./scripts/build_deb.sh ~/build-area/
cd ~/build-area
./build_deb.sh

Otherwise, try to build and install directly from source. See the Linux section below.

cd shadowsocks-libev
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

Configure and start the service

# 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

Supported distributions include

  • Fedora 22, 23, 24
  • RHEL 6, 7 and derivatives (including CentOS, Scientific Linux)

Build from source with centos

If you are using CentOS 7, you need to install these prequirement to build from source code

yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto udns-devel libev-devel libsodium-devel mbedtls-devel -y

Install from repository

Enable repo via dnf:

su -c 'dnf copr enable librehat/shadowsocks'

Or download yum repo on Fedora Copr and put it inside /etc/yum.repos.d/. The release Epel is for RHEL and its derivatives.

Then, install shadowsocks-libev via dnf:

su -c 'dnf update'
su -c 'dnf install shadowsocks-libev'

or yum:

su -c 'yum update'
su -c 'yum install shadowsocks-libev'

Archlinux

sudo pacman -S shadowsocks-libev

Please refer to downstream PKGBUILD script for extra modifications and distribution-specific bugs.

NixOS

nix-env -iA nixos.shadowsocks-libev

Nix

nix-env -iA nixpkgs.shadowsocks-libev

Linux

In general, you need the following build dependencies:

  • autotools (autoconf, automake, libtool)
  • gettext
  • pkg-config
  • libmbedtls
  • libpcre3 (old pcre library)
  • asciidoc (for documentation only)
  • xmlto (for documentation only)

For Unix-like systems, especially Debian-based systems, e.g. Ubuntu, Debian or Linux Mint, you might install build dependencies like this:

# Debian / Ubuntu
sudo apt-get install --no-install-recommends gettext build-essential autoconf libtool libpcre3-dev asciidoc xmlto automake libmbedtls-dev
# CentOS / Fedora / RHEL
sudo yum install gettext gcc autoconf libtool automake make asciidoc xmlto udns-devel libev-devel
# Arch
sudo pacman -S gettext gcc autoconf libtool automake make asciidoc xmlto udns libev
./autogen.sh && ./configure && make
sudo make install

You may need to manually install missing softwares.

FreeBSD

su
cd /usr/ports/net/shadowsocks-libev
make install

Edit your config.json file. By default, it's located in /usr/local/etc/shadowsocks-libev.

To enable shadowsocks-libev, add the following rc variable to your /etc/rc.conf file:

shadowsocks_libev_enable="YES"

Start the Shadowsocks server:

service shadowsocks_libev start

OpenWRT

The OpenWRT project is maintained here: openwrt-shadowsocks.

OS X

For OS X, use Homebrew to install or build.

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Install shadowsocks-libev:

brew install shadowsocks-libev

Usage

For a detailed and complete list of all supported arguments, you may refer to the man pages of the applications, respectively.

    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-poly1305, chacha20-ietf-poly1305
                                  salsa20, chacha20 and chacha20-ietf.

       [-f <pid_file>]            the file path to store pid

       [-t <timeout>]             socket timeout in seconds

       [-c <config_file>]         the path to config file

       [-i <interface>]           network interface to bind,
                                  not available in redir mode

       [-b <local_address>]       local address to bind

       [-u]                       enable udprelay mode,
                                  TPROXY is required in redir mode

       [-U]                       enable UDP relay and disable TCP relay,
                                  not available in local mode

       [-L <addr>:<port>]         specify destination server address and port
                                  for local port forwarding,
                                  only available in tunnel mode

       [-d <addr>]                setup name servers for internal DNS resolver,
                                  only available in server mode

       [--fast-open]              enable TCP fast open,
                                  only available in local and server mode,
                                  with Linux kernel > 3.7.0

       [--acl <acl_file>]         config file of 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

       [--executable <path>]      path to the executable of ss-server
                                  only available in manager mode

       [--plugin <name>]          Enable SIP003 plugin. (Experimental)
       [--plugin-opts <options>]  Set SIP003 plugin options. (Experimental)

       [-v]                       verbose mode

notes:

    ss-redir provides a transparent proxy function and only works on the
    Linux platform with iptables.

Advanced usage

The latest shadowsocks-libev has provided a redir mode. You can configure your Linux-based box or router to proxy all TCP traffic transparently.

# Create new chain
root@Wrt:~# iptables -t nat -N SHADOWSOCKS
root@Wrt:~# iptables -t mangle -N SHADOWSOCKS
root@Wrt:~# iptables -t mangle -N SHADOWSOCKS_MARK

# Ignore your shadowsocks server's addresses
# It's very IMPORTANT, just be careful.
root@Wrt:~# 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.
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 0.0.0.0/8 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 10.0.0.0/8 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 127.0.0.0/8 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 169.254.0.0/16 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 172.16.0.0/12 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 192.168.0.0/16 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 224.0.0.0/4 -j RETURN
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -d 240.0.0.0/4 -j RETURN

# Anything else should be redirected to shadowsocks's local port
root@Wrt:~# iptables -t nat -A SHADOWSOCKS -p tcp -j REDIRECT --to-ports 12345

# Add any UDP rules
root@Wrt:~# ip route add local default dev lo table 100
root@Wrt:~# ip rule add fwmark 1 lookup 100
root@Wrt:~# iptables -t mangle -A SHADOWSOCKS -p udp --dport 53 -j TPROXY --on-port 12345 --tproxy-mark 0x01/0x01
root@Wrt:~# iptables -t mangle -A SHADOWSOCKS_MARK -p udp --dport 53 -j MARK --set-mark 1

# Apply the rules
root@Wrt:~# iptables -t nat -A OUTPUT -p tcp -j SHADOWSOCKS
root@Wrt:~# iptables -t mangle -A PREROUTING -j SHADOWSOCKS
root@Wrt:~# iptables -t mangle -A OUTPUT -j SHADOWSOCKS_MARK

# Start the shadowsocks-redir
root@Wrt:~# ss-redir -u -c /etc/config/shadowsocks.json -f /var/run/shadowsocks.pid

Shadowsocks over KCP

It's quite easy to use shadowsocks and KCP together with kcptun.

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.

Setup your server

server_linux_amd64 -l :21 -t 127.0.0.1:443 --crypt none --mtu 1200 --nocomp --mode normal --dscp 46 &
ss-server -s 0.0.0.0 -p 443 -k passwd -m chacha20 -u

Setup your client

client_linux_amd64 -l 127.0.0.1:1090 -r <server_ip>:21 --crypt none --mtu 1200 --nocomp --mode normal --dscp 46 &
ss-local -s 127.0.0.1 -p 1090 -k passwd -m chacha20 -l 1080 -b 0.0.0.0 &
ss-local -s <server_ip> -p 443 -k passwd -m chacha20 -l 1080 -U -b 0.0.0.0

Security Tips

Although shadowsocks-libev can handle thousands of concurrent connections nicely, we still recommend setting up your server's firewall rules to limit connections from each user:

# 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

License

Copyright: 2013-2015, Clow Windy <[email protected]>
           2013-2017, Max Lv <[email protected]>
           2014, Linus Yang <[email protected]>

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.gnu.org/licenses/>.

shadowsocks-libev's People

Contributors

anonymous-contributor avatar blackgear avatar clowwindy avatar cpu avatar crvv avatar dorentus avatar eataix avatar hdid avatar hosiet avatar icpz avatar johnnysun avatar kimw avatar krazyivan- avatar librehat avatar linusyang avatar lqs avatar madeye avatar mengxd avatar mygod avatar rogers0 avatar sduponch avatar sherlock-holo avatar simonsmh avatar vfreex avatar vinna avatar vlolteanu avatar wenerme avatar windendless avatar wongsyrone avatar zhou0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

koolwiki

shadowsocks-libev's Issues

crypto.c文件里的logfile应该是linux下用的,win下会编译错误

In file included from crypto.c:36:0:
crypto.c: In function 'crypto_parse_key':
utils.h:97:30: error: unknown conversion type character 'z' in format [-Werror=format=]
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^
utils.h:97:30: note: in definition of macro 'LOGE'
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^~~~~~~~~~~~~
utils.h:97:30: error: too many arguments for format [-Werror=format-extra-args]
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^
utils.h:97:30: note: in definition of macro 'LOGE'
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^~~~~~~~~~~~~
utils.h:97:30: error: unknown conversion type character 'z' in format [-Werror=format=]
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^
utils.h:97:30: note: in definition of macro 'LOGE'
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^~~~~~~~~~~~~
utils.h:97:30: error: too many arguments for format [-Werror=format-extra-args]
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^
utils.h:97:30: note: in definition of macro 'LOGE'
fprintf(logfile, " %s ERROR: " format "\n", timestr,
^~~~~~~~~~~~~
cc1.exe: all warnings being treated as errors
make[2]: *** [Makefile:921: libshadowsocks_libev_la-crypto.lo] Error 1

请问能否编译单独exe的版本

Please answer these questions before submitting your issue. Thanks!

(Please mention that if the issue you filed is solved, you may wish to close it by yourself. Thanks again.)

(PS, you can remove 3 lines above, including this one, before post your issue.)

What version of shadowsocks-libev are you using?

What operating system are you using?

What did you do?

What did you expect to see?

What did you see instead?

What is your config in detail (with all sensitive info masked)?

Build failed, json.c error

make[2]: Entering directory '/opt/src/shadowsocks-libev/src'
CC libshadowsocks_libev_la-json.lo
CC libshadowsocks_libev_la-cache.lo
CC libshadowsocks_libev_la-acl.lo
json.c: In function 'new_value':
json.c:141:42: error: cast from pointer to integer of different size [-Werror=pointer-to-int-cast]
(state, values_size + ((unsigned long) value->u.object.values), 0)) )
^
cc1.exe: all warnings being treated as errors
make[2]: *** [Makefile:893: libshadowsocks_libev_la-json.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: Leaving directory '/opt/src/shadowsocks-libev/src'
make[1]: *** [Makefile:483: all-recursive] Error 1
make[1]: Leaving directory '/opt/src/shadowsocks-libev'
make: *** [Makefile:392: all] Error 2

还更新吗?

原版的 shadowsocks-libev 已经更新到了 3.1.3,此版本是否还继续更新?

utils.h 中的#include <syslog.h>导致win下无法通过编译

utils.h 中的#include <syslog.h>导致win下无法通过编译。退回到 clean up的commit之前就可以正常过编译了,具体应该是
#elif defined(_WIN32)

#define TIME_FORMAT "%Y-%m-%d %H:%M:%S"

#define USE_TTY()

#define USE_SYSLOG(ident)

#define LOGI(format, ...)
do {
time_t now = time(NULL);
char timestr[20];
strftime(timestr, 20, TIME_FORMAT, localtime(&now));
fprintf(stderr, " %s INFO: " format "\n", timestr, ## VA_ARGS);
fflush(stderr); }
while (0)

#define LOGE(format, ...)
do {
time_t now = time(NULL);
char timestr[20];
strftime(timestr, 20, TIME_FORMAT, localtime(&now));
fprintf(stderr, " %s ERROR: " format "\n", timestr, ## VA_ARGS);
fflush(stderr); }
while (0)

#else // not LIB_ONLY
这里的问题。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.