{"id":13480372,"url":"https://github.com/heiher/hev-socks5-tunnel","last_synced_at":"2026-02-06T07:16:04.927Z","repository":{"id":40359774,"uuid":"211069848","full_name":"heiher/hev-socks5-tunnel","owner":"heiher","description":"Tun2socks (Linux/Android/BSD/macOS/iOS/WSL2) (IPv4/IPv6/TCP/UDP)","archived":false,"fork":false,"pushed_at":"2025-05-04T00:38:19.000Z","size":426,"stargazers_count":1153,"open_issues_count":1,"forks_count":203,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-05-12T02:56:38.103Z","etag":null,"topics":["android","dns","freebsd","high-performance","ios","ipv6","linux","macos","proxy","socks5","tcp","tun-device","tun2socks","tunnel","udp"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/heiher.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-26T11:09:51.000Z","updated_at":"2025-05-11T05:21:54.000Z","dependencies_parsed_at":"2023-09-26T18:20:31.405Z","dependency_job_id":"277906db-34f4-44ba-bffc-1522d52c4268","html_url":"https://github.com/heiher/hev-socks5-tunnel","commit_stats":{"total_commits":398,"total_committers":10,"mean_commits":39.8,"dds":0.0653266331658291,"last_synced_commit":"d46a36fbf43d1540776275315596e64c8bfe60cd"},"previous_names":[],"tags_count":73,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fhev-socks5-tunnel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fhev-socks5-tunnel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fhev-socks5-tunnel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/heiher%2Fhev-socks5-tunnel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/heiher","download_url":"https://codeload.github.com/heiher/hev-socks5-tunnel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254198514,"owners_count":22030965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","dns","freebsd","high-performance","ios","ipv6","linux","macos","proxy","socks5","tcp","tun-device","tun2socks","tunnel","udp"],"created_at":"2024-07-31T17:00:38.114Z","updated_at":"2026-01-16T07:05:50.598Z","avatar_url":"https://github.com/heiher.png","language":"C","funding_links":[],"categories":["🔧 网络工具 \u0026 代理框架","C"],"sub_categories":[],"readme":"# HevSocks5Tunnel\n\n[![status](https://github.com/heiher/hev-socks5-tunnel/actions/workflows/build.yaml/badge.svg?branch=master\u0026event=push)](https://github.com/heiher/hev-socks5-tunnel)\n\nA tunnel over Socks5 proxy (tun2socks) for Unix.\n\n## Features\n\n* IPv4/IPv6. (dual stack)\n* Redirect TCP connections.\n* Redirect UDP packets. (Fullcone NAT, UDP in UDP/TCP)\n* Linux/Android/FreeBSD/macOS/iOS/WSL2.\n\n## Benchmarks\n\nSee [here](https://github.com/heiher/hev-socks5-tunnel/wiki/Benchmarks) for more details.\n\n### Speed\n\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/upload-speed.png)\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/download-speed.png)\n\n### CPU usage\n\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/upload-cpu.png)\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/download-cpu.png)\n\n### Memory usage\n\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/upload-mem.png)\n![](https://github.com/heiher/hev-socks5-tunnel/wiki/res/download-mem.png)\n\n## How to Build\n\n### Unix\n\n```bash\ngit clone --recursive https://github.com/heiher/hev-socks5-tunnel\ncd hev-socks5-tunnel\nmake\n```\n\n### Android\n\n```bash\nmkdir hev-socks5-tunnel\ncd hev-socks5-tunnel\ngit clone --recursive https://github.com/heiher/hev-socks5-tunnel jni\nndk-build\n```\n\n### iOS and macOS\n\n```bash\ngit clone --recursive https://github.com/heiher/hev-socks5-tunnel\ncd hev-socks5-tunnel\n# will generate HevSocks5Tunnel.xcframework\n./build-apple.sh\n```\n\n### Library\n\n```bash\ngit clone --recursive https://github.com/heiher/hev-socks5-tunnel\ncd hev-socks5-tunnel\n\n# Static library\nmake static\n\n# Shared library\nmake shared\n```\n\n## How to Use\n\n### Config\n\n```yaml\ntunnel:\n  # Interface name\n  name: tun0\n  # Interface MTU\n  mtu: 8500\n  # Multi-queue\n  multi-queue: false\n  # IPv4 address\n  ipv4: 198.18.0.1\n  # IPv6 address\n  ipv6: 'fc00::1'\n  # Post up script\n# post-up-script: up.sh\n  # Pre down script\n# pre-down-script: down.sh\n\nsocks5:\n  # Socks5 server port\n  port: 1080\n  # Socks5 server address (ipv4/ipv6)\n  address: 127.0.0.1\n  # Socks5 UDP relay mode (tcp|udp)\n  udp: 'udp'\n  # Socks5 handshake using pipeline mode\n# pipeline: false\n  # Socks5 server username\n# username: 'username'\n  # Socks5 server password\n# password: 'password'\n  # Socket mark\n# mark: 0\n\n#misc:\n   # task stack size (bytes)\n#  task-stack-size: 86016\n   # tcp buffer size (bytes)\n#  tcp-buffer-size: 65536\n   # connect timeout (ms)\n#  connect-timeout: 5000\n   # read-write timeout (ms)\n#  read-write-timeout: 60000\n   # stdout, stderr or file-path\n#  log-file: stderr\n   # debug, info, warn or error\n#  log-level: warn\n   # If present, run as a daemon with this pid file\n#  pid-file: /run/hev-socks5-tunnel.pid\n   # If present, set rlimit nofile; else use default value\n#  limit-nofile: 65535\n```\n\n### Run\n\n#### Linux\n\n```bash\n# Set socks5.mark = 438\nbin/hev-socks5-tunnel conf/main.yml\n\n# Bypass upstream socks5 server\nsudo ip rule add fwmark 438 lookup main pref 10\nsudo ip -6 rule add fwmark 438 lookup main pref 10\n\n# Route others\nsudo ip route add default dev tun0 table 20\nsudo ip rule add lookup 20 pref 20\nsudo ip -6 route add default dev tun0 table 20\nsudo ip -6 rule add lookup 20 pref 20\n```\n\n#### FreeBSD/macOS\n\n```zsh\n# Bypass upstream socks5 server\n# 10.0.0.1: socks5 server\n# 10.0.2.2: default gateway\nsudo route add -net 10.0.0.1/32 10.0.2.2\n\n# Route others\nsudo route change -inet default -interface utun99\nsudo route change -inet6 default -interface utun99\n```\n\n#### Low memory usage\n\nOn low-memory systems like iOS, reducing the size of the TCP buffer\nand task stack can help prevent out-of-memory issues.\n\n```yaml\nmisc:\n  # task stack size (bytes)\n  task-stack-size: 24576 # 20480 + tcp-buffer-size\n  # tcp buffer size (bytes)\n  tcp-buffer-size: 4096\n```\n\n#### Docker Compose\n\n```yaml\nversion: \"3.9\"\n\nservices:\n  client:\n    image: alpine:latest # just for network testing\n    tty: true # you can test network in terminal\n    depends_on:\n      tun:\n        condition: service_healthy\n    network_mode: \"service:tun\"\n\n  tun:\n    image: ghcr.io/heiher/hev-socks5-tunnel:latest # `latest` for the latest published version; `nightly` for the latest source build; `vX.Y.Z` for the specific version \n    cap_add:\n      - NET_ADMIN # needed\n    devices:\n      - /dev/net/tun:/dev/net/tun # needed\n    environment:\n      TUN: tun0 # optional, tun interface name, default `tun0`\n      MTU: 8500 # optional, MTU is MTU, default `8500`\n      IPV4: 198.18.0.1 # optional, tun interface ip, default `198.18.0.1`\n      TABLE: 20 # optional, ip route table id, default `20`\n      MARK: 438 # optional, ip route rule mark, dec or hex format, default `438`\n      SOCKS5_ADDR: a.b.c.d # socks5 proxy server address\n      SOCKS5_PORT: 1080 # socks5 proxy server port\n      SOCKS5_USERNAME: user # optional, socks5 proxy username, only set when need to auth\n      SOCKS5_PASSWORD: pass # optional, socks5 proxy password, only set when need to auth\n      SOCKS5_UDP_MODE: udp # optional, UDP relay mode, default `udp`, other option `tcp`\n      CONFIG_ROUTES: 1 # optional, set 0 to ignore TABLE, IPV4_INCLUDED_ROUTES and IPV4_EXCLUDED_ROUTES, with MARK defaults to 0\n      IPV4_INCLUDED_ROUTES: 0.0.0.0/0 # optional, demo means proxy all traffic. for multiple network segments, join with `,` or `\\n`\n      IPV4_EXCLUDED_ROUTES: a.b.c.d # optional, demo means exclude traffic from the proxy itself. for multiple network segments, join with `,` or `\\n`\n      LOG_LEVEL: warn # optional, default `warn`, other option `debug`/`info`/`error`\n    dns:\n      - 8.8.8.8\n```\n\nYou can also set the route rules with multiple network segments like:\n\n```yaml\n    environment:\n      IPV4_INCLUDED_ROUTES: 10.0.0.0/8,172.16.0.0/12,192.168.0.0/16\n      IPV4_EXCLUDED_ROUTES: |-\n        a.b.c.d/24\n        a.b.c.f/24\n```\n\n## API\n\n```c\n/**\n * hev_socks5_tunnel_main:\n * @config_path: config file path\n * @tun_fd: tunnel file descriptor\n *\n * Start and run the socks5 tunnel, this function will blocks until the\n * hev_socks5_tunnel_quit is called or an error occurs.\n *\n * Alias of hev_socks5_tunnel_main_from_file\n *\n * Returns: returns zero on successful, otherwise returns -1.\n *\n * Since: 2.4.6\n */\nint hev_socks5_tunnel_main (const char *config_path, int tun_fd);\n\n/**\n * hev_socks5_tunnel_main_from_file:\n * @config_path: config file path\n * @tun_fd: tunnel file descriptor\n *\n * Start and run the socks5 tunnel, this function will blocks until the\n * hev_socks5_tunnel_quit is called or an error occurs.\n *\n * Returns: returns zero on successful, otherwise returns -1.\n *\n * Since: 2.6.7\n */\nint hev_socks5_tunnel_main_from_file (const char *config_path, int tun_fd);\n\n/**\n * hev_socks5_tunnel_main_from_str:\n * @config_str: string config\n * @config_len: the byte length of string config\n * @tun_fd: tunnel file descriptor\n *\n * Start and run the socks5 tunnel, this function will blocks until the\n * hev_socks5_tunnel_quit is called or an error occurs.\n *\n * Returns: returns zero on successful, otherwise returns -1.\n *\n * Since: 2.6.7\n */\nint hev_socks5_tunnel_main_from_str (const unsigned char *config_str,\n                                     unsigned int config_len, int tun_fd);\n\n/**\n * hev_socks5_tunnel_quit:\n *\n * Stop the socks5 tunnel.\n *\n * Since: 2.4.6\n */\nvoid hev_socks5_tunnel_quit (void);\n\n/**\n * hev_socks5_tunnel_stats:\n * @tx_packets (out): transmitted packets\n * @tx_bytes (out): transmitted bytes\n * @rx_packets (out): received packets\n * @rx_bytes (out): received bytes\n *\n * Retrieve tunnel interface traffic statistics.\n *\n * Since: 2.6.5\n */\nvoid hev_socks5_tunnel_stats (size_t *tx_packets, size_t *tx_bytes,\n                              size_t *rx_packets, size_t *rx_bytes);\n```\n\n## Use Cases\n\n### Android VPN\n\n* [SocksTun](https://github.com/heiher/sockstun)\n\n### iOS\n\n* [Tun2SocksKit](https://github.com/EbrahimTahernejad/Tun2SocksKit)\n\n## Contributors\n\n* **arror** - https://github.com/arror\n* **bazuchan** - https://github.com/bazuchan\n* **dovecoteescapee** - https://github.com/dovecoteescapee\n* **ebrahimtahernejad** - https://github.com/ebrahimtahernejad\n* **heiby** - https://github.com/heiby\n* **hev** - https://hev.cc\n* **pronebird** - https://github.com/pronebird\n* **saeeddev94** - https://github.com/saeeddev94\n* **sskaje** - https://github.com/sskaje\n* **wankkoree** - https://github.com/wankkoree\n* **yiguous** - https://github.com/yiguous\n* **xz-dev** - https://github.com/xz-dev\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiher%2Fhev-socks5-tunnel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fheiher%2Fhev-socks5-tunnel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fheiher%2Fhev-socks5-tunnel/lists"}