This commit is contained in:
xjasonlyu
2020-11-07 13:33:55 +08:00
parent 39495de718
commit 36b02f7d92
+44 -18
View File
@@ -48,7 +48,7 @@
> iPerf3 tested on Debian 10 with i5-10500, 8G RAM
<img src="assets/iperf3.png" alt="iPerf3 Test" height="450px">
![iPerf3 Test](assets/iperf3.png)
## How to Build
@@ -83,7 +83,7 @@ Download from precompiled [Releases](https://github.com/xjasonlyu/tun2socks/rele
> 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)
### create docker network (macvlan mode)
```shell script
docker network create -d macvlan \
@@ -93,13 +93,15 @@ docker network create -d macvlan \
switch
```
pull `tun2socks` docker image
### pull `tun2socks` docker image
```shell script
docker pull xjasonlyu/tun2socks:latest
```
run as gateway (DNS configuration required)
### run as gateway
> DNS configuration is required.
```shell script
docker run -d \
@@ -114,7 +116,7 @@ docker run -d \
xjasonlyu/tun2socks:latest
```
or use docker-compose (recommended)
### use docker-compose (recommended)
```yaml
version: '2.4'
@@ -129,7 +131,7 @@ services:
environment:
# - GODEBUG=madvdontneed=1
- PROXY=socks5://server:port
- LOGLEVEL=warning
- LOGLEVEL=INFO
- API=api://:8080
- DNS=dns://:53
- HOSTS=localhost=127.0.0.1,router.local=172.20.1.1
@@ -158,7 +160,7 @@ networks:
<details>
<summary><b>With Linux</b></summary>
create tun
### create tun
```shell script
ip tuntap add mode tun dev tun0
@@ -166,25 +168,36 @@ ip addr add 198.18.0.1/15 dev tun0
ip link set dev tun0 up
```
add route table
### config policy routing
```shell script
ip route del default
ip route add default via 198.18.0.1 dev tun0
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
### run
> bind to a specific interface to prevent traffic looping.
```shell script
./tun2socks --loglevel WARN --device tun://tun0 --proxy socks5://server:port --interface eth0
./tun2socks --loglevel info --device tun://tun0 --proxy socks5://server:port --interface eth0
```
</details>
<details>
<summary><b>With Script</b></summary>
> entrypoint.sh would take care of tun & routes.
```shell script
PROXY=socks5://server:port LOGLEVEL=WARN sh ./scripts/entrypoint.sh
PROXY=socks5://server:port LOGLEVEL=INFO sh ./scripts/entrypoint.sh
```
</details>
@@ -194,13 +207,14 @@ PROXY=socks5://server:port LOGLEVEL=WARN sh ./scripts/entrypoint.sh
<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 |
| `/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` |
| `/connections` | DELETE | / | Close all connections |
| `/connections/{id}` | DELETE | / | Close connection by `id` |
</details>
<details>
@@ -224,6 +238,18 @@ GLOBAL OPTIONS:
--version, -v Print current version (default: false)
--help, -h show help (default: false)
```
</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