mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Chore: rewrite README
This commit is contained in:
@@ -1,291 +1,80 @@
|
||||
<h1 align="center">tun2socks</h1>
|
||||
<h3 align="center">A tun2socks powered by gVisor TCP/IP stack.</h3>
|
||||

|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/xjasonlyu/tun2socks/actions">
|
||||
<img src="https://img.shields.io/github/workflow/status/xjasonlyu/tun2socks/Go/master?style=flat-square" alt="GitHub Workflow">
|
||||
</a>
|
||||
<a href="https://hub.docker.com/r/xjasonlyu/tun2socks">
|
||||
<img src="https://img.shields.io/docker/pulls/xjasonlyu/tun2socks?style=flat-square" alt="Docker Pulls">
|
||||
</a>
|
||||
<a href="https://img.shields.io/github/go-mod/go-version/xjasonlyu/tun2socks">
|
||||
<img src="https://img.shields.io/github/go-mod/go-version/xjasonlyu/tun2socks?style=flat-square" alt="Go Version">
|
||||
</a>
|
||||
<a href="https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks">
|
||||
<img src="https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks?style=flat-square" alt="Go Report">
|
||||
</a>
|
||||
<a href="https://github.com/xjasonlyu/tun2socks/blob/master/LICENSE">
|
||||
<img src="https://img.shields.io/github/license/xjasonlyu/tun2socks?style=flat-square" alt="GitHub License">
|
||||
</a>
|
||||
<a href="https://img.shields.io/tokei/lines/github/xjasonlyu/tun2socks">
|
||||
<img src="https://img.shields.io/tokei/lines/github/xjasonlyu/tun2socks?style=flat-square" alt="Total Lines">
|
||||
</a>
|
||||
<a href="https://github.com/xjasonlyu/tun2socks/releases">
|
||||
<img src="https://img.shields.io/github/v/release/xjasonlyu/tun2socks?include_prereleases&style=flat-square" alt="Release">
|
||||
</a>
|
||||
</p>
|
||||
[![GitHub Workflow][1]](https://github.com/xjasonlyu/tun2socks/actions)
|
||||
[![Go Version][2]](https://github.com/xjasonlyu/tun2socks/blob/main/go.mod)
|
||||
[![Go Report][3]](https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks)
|
||||
[![GitHub License][4]](https://github.com/xjasonlyu/tun2socks/blob/main/LICENSE)
|
||||
[![Releases][5]](https://github.com/xjasonlyu/tun2socks/releases)
|
||||
|
||||
[1]: https://img.shields.io/github/workflow/status/xjasonlyu/tun2socks/Go/master?style=flat-square
|
||||
[2]: https://img.shields.io/github/go-mod/go-version/xjasonlyu/tun2socks?style=flat-square
|
||||
[3]: https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks?style=flat-square
|
||||
[4]: https://img.shields.io/github/license/xjasonlyu/tun2socks?style=flat-square
|
||||
[5]: https://img.shields.io/github/v/release/xjasonlyu/tun2socks?include_prereleases&style=flat-square
|
||||
|
||||
[简体中文](README_ZH.md)
|
||||
|
||||
## Features
|
||||
|
||||
- ICMP echoing
|
||||
- IPv6 support
|
||||
- ICMP echoing / IPv6 support / Socks5 & SS proxy
|
||||
- Optimized UDP transmission for game acceleration
|
||||
- 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))
|
||||
- More than 2.5Gbps throughput (10x faster than [v1](https://github.com/xjasonlyu/tun2socks/tree/v1))
|
||||
|
||||
## Requirements
|
||||
|
||||
| Target | Minimum | Recommended |
|
||||
| :----- | :-----: | :---------: |
|
||||
| System | linux darwin freebsd openbsd | linux |
|
||||
| System | Linux MacOS Freebsd OpenBSD Windows | Linux MacOS |
|
||||
| Memory | >20MB | >128MB |
|
||||
| CPU | amd64 arm64 | amd64 |
|
||||
| CPU | AMD64(x86_64) ARM64 | AMD64 with AES-NI & AVX2 |
|
||||
|
||||
## Performance
|
||||
## Documentation
|
||||
|
||||
> iPerf3 tested on Debian 10 with i5-10500, 8G RAM
|
||||
Documentations and quick start guides can be found at [Github Wiki](https://github.com/xjasonlyu/tun2socks/wiki).
|
||||
|
||||
## How to Build
|
||||
## Building from source
|
||||
|
||||
### build from source code
|
||||
Due to tun2socks based on gVisor, so only x86_64 and ARM64 was supported for now. Other architectures may become available in the future.
|
||||
|
||||
Go compiler version >= 1.15 is required
|
||||
### Dependencies
|
||||
|
||||
```text
|
||||
$ git clone https://github.com/xjasonlyu/tun2socks.git
|
||||
$ cd tun2socks
|
||||
$ make
|
||||
Make sure the following dependencies are installed:
|
||||
|
||||
- Go 1.15+
|
||||
|
||||
### Building
|
||||
|
||||
Build and install the `tun2socks` binary:
|
||||
|
||||
```shell
|
||||
make tun2socks
|
||||
sudo cp ./bin/tun2socks /usr/local/bin
|
||||
```
|
||||
|
||||
### build docker image
|
||||
Build for all architectures:
|
||||
|
||||
```text
|
||||
$ docker build -t tun2socks .
|
||||
```shell
|
||||
make all-arch
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```text
|
||||
$ docker build -t tun2socks -f .Dockerfile.aarch64 .
|
||||
```
|
||||
|
||||
## QuickStart
|
||||
|
||||
Download from precompiled [Releases](https://github.com/xjasonlyu/tun2socks/releases).
|
||||
|
||||
<details>
|
||||
<summary><b>With Docker</b></summary>
|
||||
|
||||
> 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.
|
||||
|
||||
### 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 is 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
|
||||
```
|
||||
|
||||
### use docker-compose (recommended)
|
||||
|
||||
```yaml
|
||||
version: '2.4'
|
||||
|
||||
services:
|
||||
tun2socks:
|
||||
image: xjasonlyu/tun2socks:latest
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
devices:
|
||||
- '/dev/net/tun:/dev/net/tun'
|
||||
environment:
|
||||
# - GODEBUG=madvdontneed=1
|
||||
- PROXY=socks5://server:port
|
||||
- LOGLEVEL=INFO
|
||||
- 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:
|
||||
ipv4_address: 172.20.1.2
|
||||
restart: always
|
||||
container_name: tun2socks
|
||||
|
||||
networks:
|
||||
switch:
|
||||
name: switch
|
||||
ipam:
|
||||
driver: default
|
||||
config:
|
||||
- subnet: '172.20.1.0/25'
|
||||
gateway: 172.20.1.1
|
||||
driver: macvlan
|
||||
driver_opts:
|
||||
parent: eth0
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>With Linux</b></summary>
|
||||
|
||||
### create tun
|
||||
|
||||
```shell script
|
||||
ip tuntap add mode tun dev tun0
|
||||
ip addr add 198.18.0.1/15 dev tun0
|
||||
ip link set dev tun0 up
|
||||
```
|
||||
|
||||
### config policy routing
|
||||
|
||||
```shell script
|
||||
echo "100 tun2socks" >> /etc/iproute2/rt_tables
|
||||
|
||||
ip route add default via 198.18.0.1 dev tun0 table tun2socks
|
||||
ip route add 172.17.0.0/16 dev eth0 src 172.17.0.3 table tun2socks
|
||||
ip route add 198.18.0.0/15 dev tun0 src 198.18.0.1 table tun2socks
|
||||
|
||||
ip rule add from 172.20.0.3 to 198.18.0.0/15 priority 1000 prohibit
|
||||
ip rule add from 172.20.0.3 priority 2000 table main
|
||||
ip rule add from all priority 3000 table tun2socks
|
||||
```
|
||||
|
||||
### run
|
||||
|
||||
> bind to a specific interface to prevent traffic looping.
|
||||
|
||||
```shell script
|
||||
./tun2socks --loglevel info --device tun://tun0 --proxy socks5://server:port --interface eth0
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>With MacOS</b></summary>
|
||||
|
||||
### start tun2socks
|
||||
```shell script
|
||||
./tun2socks --loglevel info --device tun://utun123 --proxy socks5://server:port --interface eth0
|
||||
```
|
||||
|
||||
### config interface
|
||||
|
||||
```shell script
|
||||
sudo ifconfig utun123 198.18.0.1 netmask 255.255.255.255 198.18.0.1 up
|
||||
```
|
||||
|
||||
### config route
|
||||
|
||||
```shell script
|
||||
sudo route del default
|
||||
sudo route add default 198.18.0.1
|
||||
sudo route add ${proxy_server_ip} ${your_gateway}
|
||||
```
|
||||
|
||||
### check route table
|
||||
|
||||
```shell script
|
||||
netstat -nr
|
||||
```
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>With Script</b></summary>
|
||||
|
||||
> entrypoint.sh would take care of tun & routes.
|
||||
|
||||
```shell script
|
||||
PROXY=socks5://server:port LOGLEVEL=INFO sh ./scripts/entrypoint.sh
|
||||
```
|
||||
</details>
|
||||
|
||||
## Details
|
||||
|
||||
<details>
|
||||
<summary><b>API Reference</b></summary>
|
||||
|
||||
| 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` |
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Help Text</b></summary>
|
||||
|
||||
```text
|
||||
Usage of tun2socks:
|
||||
-d, --device string Use this device [driver://]name
|
||||
-i, --interface string Use network INTERFACE (Darwin/Linux only)
|
||||
-l, --loglevel string Log level [debug|info|warn|error|silent] (default "info")
|
||||
-m, --mtu int Maximum transmission unit
|
||||
-p, --proxy string Use this proxy [protocol://]host[:port]
|
||||
--stats string HTTP statistic server listen address
|
||||
--token string HTTP statistic server auth token
|
||||
-v, --version Show version information and quit
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Proxy URL</b></summary>
|
||||
|
||||
| Protocol | Scheme | Examples |
|
||||
| :------- | :----- | :------- |
|
||||
| direct | `direct` | `direct://` |
|
||||
| socks5 | `socks5` | `socks5://username:password@server:port` |
|
||||
| shadowsocks | `ss`, `shadowsocks` | `ss://method:password@server:port` |
|
||||
|
||||
</details>
|
||||
|
||||
## Credits
|
||||
|
||||
- [Dreamacro/clash](https://github.com/Dreamacro/clash)
|
||||
- [google/gvisor](https://github.com/google/gvisor)
|
||||
- [majek/slirpnetstack](https://github.com/majek/slirpnetstack)
|
||||
- [WireGuard/wireguard-go](https://github.com/WireGuard/wireguard-go)
|
||||
- [WireGuard/wireguard-go](https://git.zx2c4.com/wireguard-go)
|
||||
|
||||
## 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).
|
||||
Due to the implementation of pure Go, the memory consumption is higher than the previous version.
|
||||
If you are sensitive to it, please go back to [v1](https://github.com/xjasonlyu/tun2socks/tree/v1).
|
||||
|
||||
## TODO
|
||||
|
||||
- [x] Windows support
|
||||
- [x] FreeBSD support
|
||||
- [x] OpenBSD support
|
||||
- [ ] Auto route mode
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||

|
||||
|
||||
[![GitHub Workflow][1]](https://github.com/xjasonlyu/tun2socks/actions)
|
||||
[![Go Version][2]](https://github.com/xjasonlyu/tun2socks/blob/main/go.mod)
|
||||
[![Go Report][3]](https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks)
|
||||
[![GitHub License][4]](https://github.com/xjasonlyu/tun2socks/blob/main/LICENSE)
|
||||
[![Releases][5]](https://github.com/xjasonlyu/tun2socks/releases)
|
||||
|
||||
[1]: https://img.shields.io/github/workflow/status/xjasonlyu/tun2socks/Go/master?style=flat-square
|
||||
[2]: https://img.shields.io/github/go-mod/go-version/xjasonlyu/tun2socks?style=flat-square
|
||||
[3]: https://goreportcard.com/badge/github.com/xjasonlyu/tun2socks?style=flat-square
|
||||
[4]: https://img.shields.io/github/license/xjasonlyu/tun2socks?style=flat-square
|
||||
[5]: https://img.shields.io/github/v/release/xjasonlyu/tun2socks?include_prereleases&style=flat-square
|
||||
|
||||
[English](README.md)
|
||||
|
||||
## 特性
|
||||
|
||||
- ICMP 回应 / IPv6 支持 / Socks5 和 SS 代理
|
||||
- 适用于游戏加速,由专门优化过UDP流量的传输
|
||||
- 纯 Go 实现,编译不再需要 CGO 的加持
|
||||
- 路由模式,可以用来转发代理局域网内所有流量
|
||||
- 由 [gVisor](https://github.com/google/gvisor) 强力驱动的 TCP/IP 网络栈
|
||||
- 实测超过 2.5Gbps 的带宽吞吐量( [v1](https://github.com/xjasonlyu/tun2socks/tree/v1) 版本的10x倍以上)
|
||||
|
||||
## 硬件需求
|
||||
|
||||
| 目标 | 最小 | 建议 |
|
||||
| :----- | :-----: | :---------: |
|
||||
| 系统 | Linux MacOS Freebsd OpenBSD Windows | Linux MacOS |
|
||||
| 内存 | >20MB | >128MB |
|
||||
| 架构 | AMD64(x86_64) ARM64 | AMD64 with AES-NI & AVX2 |
|
||||
|
||||
## 文档
|
||||
|
||||
文档以及使用方式,请看 [Github Wiki](https://github.com/xjasonlyu/tun2socks/wiki) 。
|
||||
|
||||
## 从源码编译
|
||||
|
||||
由于 tun2socks 是基于 gVisor的,所以目前只支持 x86_64 和 ARM64 架构。以后可能会支持其他的架构(取决于gVisor)。
|
||||
|
||||
### 环境依赖
|
||||
|
||||
确保安装了以下环境:
|
||||
|
||||
- Go 1.15+
|
||||
|
||||
### 开始编译
|
||||
|
||||
编译以及安装 `tun2socks` 二进制文件:
|
||||
|
||||
```shell
|
||||
make tun2socks
|
||||
sudo cp ./bin/tun2socks /usr/local/bin
|
||||
```
|
||||
|
||||
编译所有架构的二进制文件:
|
||||
|
||||
```shell
|
||||
make all-arch
|
||||
```
|
||||
|
||||
## 感谢
|
||||
|
||||
- [Dreamacro/clash](https://github.com/Dreamacro/clash)
|
||||
- [google/gvisor](https://github.com/google/gvisor)
|
||||
- [majek/slirpnetstack](https://github.com/majek/slirpnetstack)
|
||||
- [WireGuard/wireguard-go](https://git.zx2c4.com/wireguard-go)
|
||||
|
||||
## 已知问题
|
||||
|
||||
由于采用了纯Go实现,所以这一版本的内存消耗通常会高于上一个版本(在有大量连接时更为明显)。
|
||||
如果您的需求对内存消耗极为敏感,请继续使用 [v1](https://github.com/xjasonlyu/tun2socks/tree/v1) 版本。
|
||||
|
||||
## TODO
|
||||
|
||||
- [x] Windows 支持
|
||||
- [x] FreeBSD 支持
|
||||
- [x] OpenBSD 支持
|
||||
- [ ] 自动路由模式
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
Reference in New Issue
Block a user