diff --git a/README.md b/README.md index 13cc916..5325e8c 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,37 @@ -# tun2socks +

tun2socks

+

A tun2socks implementation written in Go.

-![GitHub Workflow Status](https://img.shields.io/github/workflow/status/xjasonlyu/tun2socks/Go/master?style=flat-square) -![Go report](https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks?style=flat-square) -![GitHub License](https://img.shields.io/github/license/xjasonlyu/tun2socks?style=flat-square) -![Lines of code](https://img.shields.io/tokei/lines/github/xjasonlyu/tun2socks?style=flat-square) -![Release](https://img.shields.io/github/v/release/xjasonlyu/tun2socks.svg?include_prereleases&style=flat-square) - -A tun2socks implementation written in Go. +

+ + GitHub Workflow + + + Docker Pulls + + + Go Version + + + Go Report + + + GitHub License + + + Total Lines + + + Release + +

## Features +- ICMP echoing - IPv6 support - Optimized UDP transmission for game acceleration -- Pure Go implementation, no CGO required +- Pure Go implementation, no more CGO required +- Router mode, routing all the traffic in LAN - Socks5, Shadowsocks protocol support for remote connections - TCP/IP stack powered by [gVisor](https://github.com/google/gvisor) - Up to 2.5Gbps throughput (10x faster than [v1](https://github.com/xjasonlyu/tun2socks/tree/v1)) @@ -25,16 +44,77 @@ A tun2socks implementation written in Go. | Memory | >20MB | >128MB | | CPU | amd64 arm64 | amd64 | +## Performance + +> iPerf3 tested on Debian 10 with i5-10500, 8G RAM + +iPerf3 Test + +## How to Build + +### build from source code + +Go compiler version >= 1.15 is required + +```text +$ git clone https://github.com/xjasonlyu/tun2socks.git +$ cd tun2socks +$ make +``` + +### build docker image + +```text +$ docker build -t tun2socks . +``` + +or + +```text +$ docker build -t tun2socks -f ./docker/Dockerfile.aarch64 . +``` + ## QuickStart Download from precompiled [Releases](https://github.com/xjasonlyu/tun2socks/releases).
- With Docker + With Docker > Since Go 1.12, the runtime now uses MADV_FREE to release unused memory on **linux**. This is more efficient but may result in higher reported RSS. The kernel will reclaim the unused data when it is needed. To revert to the Go 1.11 behavior (MADV_DONTNEED), set the environment variable GODEBUG=madvdontneed=1. -docker-compose.yml +create docker network (macvlan mode) + +```shell script +docker network create -d macvlan \ + --subnet=172.20.1.0/25 \ + --gateway=172.20.1.1 \ + -o parent=eth0 \ + switch +``` + +pull `tun2socks` docker image + +```shell script +docker pull xjasonlyu/tun2socks:latest +``` + +run as gateway (DNS configuration required) + +```shell script +docker run -d \ + --network switch \ + --name tun2socks \ + --ip 172.20.1.2 \ + --privileged \ + --restart always \ + --sysctl net.ipv4.ip_forward=1 \ + -e PROXY=socks5://server:port \ + -e KEY=VALUE... \ + xjasonlyu/tun2socks:latest +``` + +or use docker-compose (recommended) ```yaml version: '2.4' @@ -50,10 +130,10 @@ services: # - GODEBUG=madvdontneed=1 - PROXY=socks5://server:port - LOGLEVEL=warning - - API=:8080 - - DNS=:53 - - HOSTS= - - EXCLUDED= + - API=api://:8080 + - DNS=dns://:53 + - HOSTS=localhost=127.0.0.1,router.local=172.20.1.1 + - EXCLUDED=1.1.1.1,1.0.0.1 - EXTRACMD= networks: switch: @@ -76,7 +156,7 @@ networks:
- With Linux + With Linux create tun @@ -86,7 +166,7 @@ ip addr add 198.18.0.1/15 dev tun0 ip link set dev tun0 up ``` -add route +add route table ```shell script ip route del default @@ -101,26 +181,30 @@ run
- With Script + With Script ```shell script PROXY=socks5://server:port LOGLEVEL=WARN sh ./scripts/entrypoint.sh ```
-## Build from source +## Details -```text -$ git clone https://github.com/xjasonlyu/tun2socks.git -$ cd tun2socks -$ make -``` +
+ API Reference -## Performance +| Path | Methods | Parameters | Description | +| :--- | :------ | :--------- | :---------- | +| `/logs` | GET | `level` | Get real-time logs | +| `/traffic` | GET | | Get real-time traffic data | +| `/version` | GET | | Get current version | +| `/connections` | GET | `interval` | Get all connections | +| `/connections` | DELETE | | Close all connections | +| `/connections/{id}` | DELETE | | Close connection by `id` | +
-![iperf3 test](assets/iperf3.png) - -## Usage +
+ Help Text ```text NAME: @@ -140,18 +224,19 @@ GLOBAL OPTIONS: --version, -v Print current version (default: false) --help, -h show help (default: false) ``` - -## Known Issues - -Due to the implementation of pure Go, the memory usage is higher than the previous version. -If you are memory sensitive, please go back to [v1](https://github.com/xjasonlyu/tun2socks/tree/v1). - -## TODO - -- [ ] Windows support +
## Credits - [Dreamacro/clash](https://github.com/Dreamacro/clash) - [google/gvisor](https://github.com/google/gvisor) - [majek/slirpnetstack](https://github.com/majek/slirpnetstack) + +## Known Issues + +Due to the implementation of pure Go, the memory usage is higher than the previous version. +If you are sensitive to memory, please go back to [v1](https://github.com/xjasonlyu/tun2socks/tree/v1). + +## TODO + +- [ ] Windows support diff --git a/assets/iperf3.png b/assets/iperf3.png index c44182d..48a5b10 100644 Binary files a/assets/iperf3.png and b/assets/iperf3.png differ