A lightweight, fast and reliable tun2socks
A simple, lightweight tunnel over Socks5 proxy (tun2socks).
See here for more details.
git clone --recursive https://github.com/heiher/hev-socks5-tunnel
cd hev-socks5-tunnel
makemkdir hev-socks5-tunnel
cd hev-socks5-tunnel
git clone --recursive https://github.com/heiher/hev-socks5-tunnel jni
ndk-buildgit clone --recursive https://github.com/heiher/hev-socks5-tunnel
cd hev-socks5-tunnel
# will generate HevSocks5Tunnel.xcframework
./build-apple.shexport MSYS=winsymlinks:native
git clone --recursive https://github.com/heiher/hev-socks5-tunnel
cd hev-socks5-tunnel
makegit clone --recursive https://github.com/heiher/hev-socks5-tunnel
cd hev-socks5-tunnel
# Static library
make static
# Shared library
make shared…# Set socks5.mark = 438
bin/hev-socks5-tunnel conf/main.yml
# Disable reverse path filter
sudo sysctl -w net.ipv4.conf.all.rp_filter=0
sudo sysctl -w net.ipv4.conf.tun0.rp_filter=0
# Bypass upstream socks5 server
sudo ip rule add fwmark 438 lookup main pref 10
sudo ip -6 rule add fwmark 438 lookup main pref 10
# Route others
sudo ip route add default dev tun0 table 20
sudo ip rule add lookup 20 pref 20
sudo ip -6 route add default dev tun0 table 20
sudo ip -6 rule add lookup 20 pref 20# Bypass upstream socks5 server
# 10.0.0.1: socks5 server
# 10.0.2.2: default gateway
sudo route add -net 10.0.0.1/32 10.0.2.2
# Route others
sudo route change -inet default -interface tun0
sudo route change -inet6 default -interface tun0# Bypass upstream socks5 server
# 10.0.0.1: socks5 server
# 10.0.2.2: default gateway
route add 10.0.0.1/32 10.0.2.2
# Route others
route change 0.0.0.0/0 0.0.0.0 if tun-index
route change ::/0 :: if tun-indexRepo: https://github.com/openwrt/packages/tree/master/net/hev-socks5-tunnel
# Install package
opkg install hev-socks5-tunnel
# Edit /etc/config/hev-socks5-tunnel
# Restart service
/etc/init.d/hev-socks5-tunnel restartOn low-memory systems like iOS, reducing the size of the TCP buffer and task stack, as well as limiting the maximum session count, can help prevent out-of-memory issues.
misc:
# task stack size (bytes)
task-stack-size: 24576 # 20480 + tcp-buffer-size
# tcp buffer size (bytes)
tcp-buffer-size: 4096
# maximum session count
max-session-count: 1200…You can also set the route rules with multiple network segments like:
environment:
IPV4_INCLUDED_ROUTES: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
IPV4_EXCLUDED_ROUTES: |-
a.b.c.d/24
a.b.c.f/24…public class TProxyService {
private static native boolean TProxyStartService(String config_path, int fd);
private static native boolean TProxyStopService();
private static native boolean TProxyIsRunning();
private static native long[] TProxyGetStats();
static {
System.loadLibrary("hev-socks5-tunnel");
}
}object TProxyService {
private external fun TProxyStartService(config_path: String, fd: Int): Boolean
private external fun TProxyStopService(): Boolean
private external fun TProxyIsRunning(): Boolean
private external fun TProxyGetStats(): LongArray
init {
System.loadLibrary("hev-socks5-tunnel")
}
}Allow overriding the package and class names in Application.mk[^2].
APP_CFLAGS := -DPKGNAME=hev/sockstun -DCLSNAME=TProxyServiceThe Android CI job also produces an AAR (hev-socks5-tunnel.aar, containing all four ABIs)
built with the default JNI contract — no PKGNAME/CLSNAME overrides — so its natives
register to hev.htproxy.TProxyService. The AAR is generic: instead of rebuilding it per
consumer package, add a small shim class in your app:
// app/src/main/java/hev/htproxy/TProxyService.kt
package hev.htproxy
object TProxyService {
external fun TProxyStartService(config_path: String, fd: Int): Boolean
external fun TProxyStopService(): Boolean
external fun TProxyIsRunning(): Boolean
external fun TProxyGetStats(): LongArray
init {
System.loadLibrary("hev-socks5-tunnel")
}
}Then call these methods from your own code; no per-package rebuild is required. The AAR is
also attached to tagged releases. Consumers that need a custom package or class name can
still override PKGNAME/CLSNAME in Application.mk as shown above and build themselves.
MIT
[^1]: See protocol specification. The hev-socks5-server supports UDP relay over TCP. [^2]: See Application.mk
No open issues yet, or sync has not completed.