A simple VPN written in Go.
Go to file
net-byte cedf869df9
Merge pull request #102 from hulucc/master
fix: better command err info
2023-09-25 13:33:21 +08:00
.github/workflows add docker build 2023-08-30 01:06:19 +08:00
app update version info 2023-08-27 23:28:47 +08:00
certs add default cert 2022-05-17 19:59:44 +08:00
common fix: better command err info 2023-09-25 11:48:31 +08:00
example support for loading default settings from configuration files 2023-08-25 19:05:43 +08:00
mobile move the version information to the common package. 2023-08-25 19:18:14 +08:00
register optimise code. 2023-07-14 14:46:03 +08:00
scripts update version 2023-09-09 00:29:56 +08:00
transport fix: Repair variable name changes issue. 2023-09-12 16:47:58 +08:00
.gitignore fix: ignore vtun binary by gitignore 2023-08-26 00:25:59 +08:00
.travis.yml Update .travis.yml 2023-08-25 21:13:40 +08:00
Dockerfile update dockerfile 2022-04-13 22:25:12 +08:00
go.mod add Makefile for building mobile libs 2023-08-26 23:43:22 +08:00
go.sum add Makefile for building mobile libs 2023-08-26 23:43:22 +08:00
LICENSE Add vtun 2020-10-27 22:17:50 +08:00
main.go optimize code. 2023-08-25 20:20:10 +08:00
Makefile test: add xor ut 2023-08-29 10:53:06 +08:00
README_CN.md fix doc 2023-08-26 23:53:33 +08:00
README.md fix doc 2023-08-26 23:53:33 +08:00

vtun

A simple VPN written in Go.

EN | 中文

Travis Go Report Card image image image

Features

  • VPN over udp
  • VPN over websocket
  • VPN over tls
  • VPN over grpc
  • VPN over quic
  • VPN over kcp
  • VPN over utls
  • VPN over dtls
  • VPN over h2
  • VPN over http
  • VPN over tcp
  • VPN over https

Usage

Usage of vtun:
  -S  server mode
  -c string
      tun interface cidr (default "172.16.0.10/24")
  -c6 string
      tun interface ipv6 cidr (default "fced:9999::9999/64")
  -certificate string
      tls certificate file path (default "./certs/server.pem")
  -compress
      enable data compression
  -dn string
      device name
  -f string
      config file
  -g  client global mode
  -host string
      http host
  -isv
      tls insecure skip verify
  -k string
      key (default "freedom@2023")
  -l string
      local address (default ":3000")
  -mtu int
      tun mtu (default 1500)
  -obfs
      enable data obfuscation
  -p string
      protocol udp/tls/grpc/quic/utls/dtls/h2/http/tcp/https/ws/wss (default "udp")
  -path string
      websocket path (default "/freedom")
  -privatekey string
      tls certificate key file path (default "./certs/server.key")
  -psk
      enable psk mode (dtls only)
  -s string
      server address (default ":3001")
  -sip string
      server ip (default "172.16.0.1")
  -sip6 string
      server ipv6 (default "fced:9999::1")
  -sni string
      tls handshake sni
  -t int
      dial timeout in seconds (default 30)
  -v  enable verbose output

Build

scripts/build.sh

Client on Linux

sudo ./vtun-linux-amd64 -s server-addr:3001 -c 172.16.0.10/24 -k 123456

Client on Linux with global mode(routing all your traffic to server)

sudo ./vtun-linux-amd64 -s server-addr:3001 -c 172.16.0.10/24 -k 123456 -g

Client on MacOS

sudo ./vtun-darwin-amd64 -s server-addr:3001 -c 172.16.0.10/24 -k 123456 -g -sip 172.16.0.1

Client on Windows

To use it with windows, you will need to download a wintun.dll file in the app directory.
Open powershell as administrator and run cmd:

.\vtun-win-amd64.exe  -s server-addr:3001 -c 172.16.0.10/24 -k 123456 -g -sip 172.16.0.1

Server on Linux

sudo ./vtun-linux-amd64 -S -l :3001 -c 172.16.0.1/24 -k 123456

Iptables setup on Linux server

  # Enable ipv4 and ipv6 forward
  vi /etc/sysctl.conf
  net.ipv4.ip_forward = 1
  net.ipv6.conf.all.forwarding=1
  sysctl -p /etc/sysctl.conf
  # Masquerade outgoing traffic
  iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
  # Allow return traffic
  iptables -A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  iptables -A INPUT -i tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
  # Forward everything
  iptables -A FORWARD -j ACCEPT

Docker

docker image

Run client

docker run  -d --privileged --restart=always --net=host --name vtun-client \
netbyte/vtun -s server-addr:3001 -c 172.16.0.10/24 -k 123456

Run client with global mode

docker run  -d --privileged --restart=always --net=host --name vtun-client \
netbyte/vtun -s server-addr:3001 -c 172.16.0.10/24 -k 123456 -g

Run server

docker run  -d --privileged --restart=always --net=host --name vtun-server \
netbyte/vtun -S -l :3001 -c 172.16.0.1/24 -k 123456

How to build mobile libs

1. install gomobile

go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init

2. install android ndk

3. build android .aar file

make android

Mobile client

1. vTunnel

2. GoFly VPN

License

The MIT License (MIT)

Acknowledgments

Thanks JetBrains for providing licenses.

JetBrains Logo (Main) logo.