2021-09-02 11:30:23 +02:00
|
|
|
# tun2proxy
|
|
|
|
Tunnel TCP traffic through SOCKS5 or HTTP on Linux.
|
|
|
|
|
|
|
|
**Authentication not yet supported. Error handling incomplete and too restrictive.**
|
|
|
|
|
|
|
|
## Build
|
|
|
|
Clone the repository and `cd` into the project folder. Then run the following:
|
|
|
|
```
|
|
|
|
cargo build --release
|
|
|
|
```
|
|
|
|
|
|
|
|
## Setup
|
|
|
|
A standard setup, which would route all traffic from your system through the tunnel interface, could look as follows:
|
2022-08-17 00:04:08 +02:00
|
|
|
```shell
|
|
|
|
# Define the proxy endpoint.
|
|
|
|
PROXY_IP=1.2.3.4
|
|
|
|
PROXY_PORT=1080
|
|
|
|
|
|
|
|
# Create a tunnel interface named tun0 which your user can bind to, so we don't need to run tun2proxy as root.
|
2021-09-02 11:30:23 +02:00
|
|
|
sudo ip tuntap add name tun0 mode tun user $USER
|
|
|
|
sudo ip link set tun0 up
|
|
|
|
|
2022-08-17 00:04:08 +02:00
|
|
|
# To prevent a routing loop, we add a route to the proxy server that behaves like the default route.
|
|
|
|
sudo ip route add "$PROXY_IP" $(ip route | grep '^default' | cut -d ' ' -f 2-)
|
2021-09-02 11:30:23 +02:00
|
|
|
|
|
|
|
# Route all your traffic through tun0 without interfering with the default route.
|
2021-09-03 15:12:13 +02:00
|
|
|
sudo ip route add 128.0.0.0/1 dev tun0
|
2021-09-02 11:30:23 +02:00
|
|
|
sudo ip route add 0.0.0.0/1 dev tun0
|
|
|
|
|
2022-08-17 00:04:08 +02:00
|
|
|
./target/release/tun2proxy --tun tun0 --socks5 "$PROXY_IP:$PROXY_PORT"
|
2021-09-02 11:30:23 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
Note that if you paste these commands into a shell script, which you then run with `sudo`, you might want to replace
|
|
|
|
`$USER` with `$SUDO_USER`.
|
|
|
|
|
2022-08-17 00:04:08 +02:00
|
|
|
For DNS to work, you might need an additional tool like [dnsproxy](https://github.com/AdguardTeam/dnsproxy) that is
|
|
|
|
configured to listen on a local UDP port and communicates with the upstream DNS server via TCP.
|
|
|
|
|
2021-09-02 11:30:23 +02:00
|
|
|
## CLI
|
|
|
|
```
|
|
|
|
Tunnel interface to proxy.
|
|
|
|
|
2023-03-20 14:16:07 +08:00
|
|
|
Usage: tun2proxy --tun <TUN> --proxy <PROXY_TYPE> --addr <ADDR>
|
2021-09-02 11:30:23 +02:00
|
|
|
|
2023-03-20 14:16:07 +08:00
|
|
|
Options:
|
2023-03-20 15:09:19 +08:00
|
|
|
-t, --tun <TUN> Name of the tun interface
|
|
|
|
-p, --proxy <PROXY_TYPE> What proxy type to run [possible values: socks5, http]
|
|
|
|
-a, --addr <ADDR> Server address with format IP:PORT
|
|
|
|
-h, --help Print help (see more with '--help')
|
|
|
|
-V, --version Print version
|
2022-08-17 00:04:08 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## TODO
|
|
|
|
- Authentication for SOCKS (plain) and HTTP (base64)
|
|
|
|
- UDP support for SOCKS
|
|
|
|
- Virtual DNS
|