Skip to content

smartethnet/rustun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

37 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒ Rustun

AI-Driven Intelligent VPN Tunnel


License: MIT Rust Build Status Release Downloads Stars

๐ŸŒ Website ยท ๐Ÿ“– Documentation ยท ไธญๆ–‡ๆ–‡ๆกฃ ยท ๐Ÿ› Report Bug ยท โœจ Request Feature

Platform Clients: ๐Ÿ“ฑ iOS ยท ๐Ÿค– Android ยท ๐ŸชŸ Windows ยท ๐ŸŽ macOS ยท ๐Ÿง Linux


An AI-driven intelligent VPN tunnel built with Rust, featuring automatic path selection and smart routing capabilities.

Status: Actively Developing ๐Ÿšง

Architecture

โœจ Key Features

  • ๐Ÿ”“ Open Source - MIT License, completely free and transparent
  • โšก Simple & Fast - One command to start: ./client -s SERVER:8080 -i client-001
  • ๐Ÿข Multi-Tenant - Cluster-based isolation for multiple teams or business units
  • ๐Ÿ” Secure Encryption - ChaCha20-Poly1305 (default), AES-256-GCM, XOR/Plain options
  • ๐Ÿš€ Dual-Path P2P - IPv6 direct connection + STUN hole punching with auto-fallback to relay
  • ๐ŸŒ Smart Routing - Automatic path selection: IPv6 (lowest latency) โ†’ STUN (NAT traversal) โ†’ Relay
  • ๐ŸŒ Cross-Platform - Linux, macOS, Windows with pre-built binaries

๐Ÿ“‹ Table of Contents

For Users

For Developers

Roadmap

๐Ÿš€ Quick Start

One-Click Installation (Recommended)

Server Installation:

# Automatically installs the latest version
curl -fsSL https://raw.githubusercontent.com/smartethnet/rustun/main/install.sh | sudo bash

# Configure
sudo vim /etc/rustun/server.toml
sudo vim /etc/rustun/routes.json

# Start service
sudo systemctl start rustun-server
sudo systemctl enable rustun-server

Download Pre-built Binaries

Download from GitHub Releases

Available Platforms:

  • Linux: x86_64 (glibc/musl), ARM64 (glibc/musl)
  • macOS: Intel (x86_64), Apple Silicon (ARM64)
  • Windows: x86_64 (MSVC)

Each release includes:

  • server - VPN server binary
  • client - VPN client binary
  • server.toml.example - Server configuration template
  • routes.json.example - Routes configuration template

Prerequisites

All Platforms:

  • Root/Administrator privileges (required for TUN device and routing)

Windows Only:

  • Wintun driver - extract wintun.dll to the same directory as binaries

Linux/macOS:

  • TUN/TAP driver support (usually pre-installed)

๐Ÿ“ฆ Installation

Method 1: One-Click Script (Server Only)

# Install latest version
curl -fsSL https://raw.githubusercontent.com/smartethnet/rustun/main/install.sh | sudo bash

What it does:

  • โœ… Detects your system automatically (Ubuntu/Debian/CentOS/Fedora/Arch)
  • โœ… Downloads the correct binary for your architecture
  • โœ… Installs to /usr/local/bin/rustun-server
  • โœ… Creates configuration directory /etc/rustun/
  • โœ… Sets up systemd service for auto-start
  • โœ… Configures automatic restart on failure

Post-installation:

# Edit server configuration
sudo vim /etc/rustun/server.toml

# Edit routes configuration  
sudo vim /etc/rustun/routes.json

# Start server
sudo systemctl start rustun-server

# Enable auto-start on boot
sudo systemctl enable rustun-server

# Check status
sudo systemctl status rustun-server

# View logs
sudo journalctl -u rustun-server -f

Method 2: Manual Installation (Client & Server)

Step 1: Download

# Go to releases page and download for your platform
# https://github.com/smartethnet/rustun/releases/latest

# Example for Linux x86_64
wget https://github.com/smartethnet/rustun/releases/latest/download/rustun-x86_64-unknown-linux-gnu.tar.gz
tar xzf rustun-x86_64-unknown-linux-gnu.tar.gz
cd rustun-*

Step 2: Run

# Start server (Linux/macOS)
sudo ./server server.toml.example

# Start client (Linux/macOS)
sudo ./client -s SERVER_IP:8080 -i client-001

Windows:

# 1. Download rustun-x86_64-pc-windows-msvc.zip
# 2. Extract to a folder
# 3. Download Wintun from https://www.wintun.net/
# 4. Extract wintun.dll to the same folder
# 5. Run as Administrator:

.\server.exe server.toml.example
# or
.\client.exe -s SERVER_IP:8080 -i client-001

โš™๏ธ Configuration

Server Configuration

Create or edit /etc/rustun/server.toml:

[server_config]
# Server listening address
listen_addr = "0.0.0.0:8080"

[crypto_config]
# Encryption method (choose one):

# ChaCha20-Poly1305 (Recommended - high security, great performance)
chacha20poly1305 = "your-secret-key-here"

# AES-256-GCM (Hardware accelerated on modern CPUs)
# aes256gcm = "your-secret-key-here"

# XOR (Lightweight, for testing only)
# xor = "test-key"

# Plain (No encryption, debugging only)
# crypto_config=plain

[route_config]
# Path to routes configuration file
routes_file = "/etc/rustun/routes.json"

Routes Configuration

Create or edit /etc/rustun/routes.json:

[
  {
    "cluster": "production",
    "identity": "prod-gateway-01",
    "private_ip": "10.0.1.1",
    "mask": "255.255.255.0",
    "gateway": "10.0.1.254",
    "ciders": ["192.168.100.0/24", "192.168.101.0/24"]
  },
  {
    "cluster": "production",
    "identity": "prod-app-server-01",
    "private_ip": "10.0.1.2",
    "mask": "255.255.255.0",
    "gateway": "10.0.1.254",
    "ciders": []
  }
]

Field Descriptions:

Field Description Example
cluster Logical group for multi-tenancy isolation "production"
identity Unique client identifier "prod-app-01"
private_ip Virtual IP assigned to the client "10.0.1.1"
mask Subnet mask for the VPN network "255.255.255.0"
gateway Gateway IP for routing "10.0.1.254"
ciders CIDR ranges routable through this client ["192.168.1.0/24"]

๐Ÿ“– Usage

Starting the Server

Using systemd (if installed with script):

sudo systemctl start rustun-server
sudo systemctl status rustun-server
sudo journalctl -u rustun-server -f

Running manually:

# Linux/macOS
sudo ./server /etc/rustun/server.toml

# Windows (as Administrator)
.\server.exe server.toml

Connecting Clients

Basic Connection:

# Linux/macOS
sudo ./client -s SERVER_IP:8080 -i client-identity

# Windows (as Administrator)
.\client.exe -s SERVER_IP:8080 -i client-identity

Examples:

# Production gateway
./client -s 192.168.1.100:8080 -i prod-gateway-01

# Development workstation
./client -s vpn.example.com:8080 -i dev-workstation-01

# With custom encryption
./client -s SERVER:8080 -i client-001 -c chacha20:my-secret-key

Client Options

./client --help

Common Options:

Option Description Example
-s, --server Server address -s 192.168.1.100:8080
-i, --identity Client identity -i prod-app-01
-c, --crypto Encryption method -c chacha20:my-key
--enable-p2p Enable P2P mode --enable-p2p
--keepalive-interval Keepalive interval (seconds) --keepalive-interval 10

Encryption Options

# ChaCha20-Poly1305 (Default, Recommended)
./client -s SERVER:8080 -i client-001 -c chacha20:my-secret-key

# AES-256-GCM (Hardware accelerated)
./client -s SERVER:8080 -i client-001 -c aes256:my-secret-key

# XOR (Lightweight, testing only)
./client -s SERVER:8080 -i client-001 -c xor:test-key

# Plain (No encryption, debugging only)
./client -s SERVER:8080 -i client-001 -c plain

๐Ÿš€ P2P Direct Connection

Enable P2P for direct peer-to-peer connections with automatic intelligent path selection:

./client -s SERVER:8080 -i client-001 --enable-p2p

Connection Strategy

Rustun uses a three-tier intelligent routing strategy:

  1. ๐ŸŒ IPv6 Direct Connection (Primary Path)

    • Lowest latency, highest throughput
    • Works when both peers have global IPv6 addresses
    • Automatic connection establishment
  2. ๐Ÿ”„ STUN Hole Punching (Secondary Path)

    • NAT traversal for IPv4 networks
    • Works across most NAT types
    • Automatic fallback when IPv6 unavailable
  3. ๐Ÿ“ก Relay Mode (Fallback)

    • Via server when P2P fails
    • Guaranteed connectivity
    • Automatic failover

๐Ÿข Multi-Tenant Isolation

Rustun supports cluster-based multi-tenancy for complete network isolation between different teams or business units.

How It Works

  • Each client belongs to a cluster
  • Clients can only communicate with peers in the same cluster
  • Different clusters use separate IP ranges
  • Perfect for isolating production, staging, and development environments

Configuration Example

routes.json:

[
  {
    "cluster": "production",
    "identity": "prod-gateway",
    "private_ip": "10.0.1.1",
    "mask": "255.255.255.0",
    "gateway": "10.0.1.254",
    "ciders": ["192.168.100.0/24"]
  },
  {
    "cluster": "production",
    "identity": "prod-app-01",
    "private_ip": "10.0.1.2",
    "mask": "255.255.255.0",
    "gateway": "10.0.1.254",
    "ciders": []
  },
  {
    "cluster": "development",
    "identity": "dev-workstation-01",
    "private_ip": "10.0.2.1",
    "mask": "255.255.255.0",
    "gateway": "10.0.2.254",
    "ciders": []
  },
  {
    "cluster": "development",
    "identity": "dev-workstation-02",
    "private_ip": "10.0.2.2",
    "mask": "255.255.255.0",
    "gateway": "10.0.2.254",
    "ciders": []
  }
]

Result

  • โœ… Production clients can only communicate within 10.0.1.0/24 network
  • โœ… Development clients are isolated in 10.0.2.0/24 network
  • โœ… No cross-cluster communication possible
  • โœ… Each team has complete network independence

๐Ÿ’ผ Use Cases

Rustun is designed for various networking scenarios. Here are common use cases:

Use Case Description Key Benefits Typical Setup
๐Ÿข Remote Office Connectivity Connect multiple office locations with site-to-site VPN โ€ข Seamless resource sharing
โ€ข P2P optimization reduces latency
โ€ข Multi-tenant support for departments
One server + gateway client per office
๐Ÿ‘จโ€๐Ÿ’ป Secure Remote Work Enable secure remote access for employees working from home โ€ข Encrypted connections from anywhere
โ€ข P2P reduces server load
โ€ข Easy user management via routes.json
One server + client per employee
๐Ÿ”€ Multi-Environment Isolation Separate networks for production, staging, and development โ€ข Zero risk of cross-environment access
โ€ข Same infrastructure for all envs
โ€ข Easy configuration replication
One server + separate cluster per environment
๐Ÿค– IoT Device Management Securely connect and manage IoT devices across locations โ€ข Encrypted device communication
โ€ข Direct P2P for low-latency control
โ€ข Scalable to thousands of devices
One server + lightweight client per gateway
๐ŸŽฎ Gaming Server Network Low-latency network for game servers across regions โ€ข P2P ensures sub-10ms latency
โ€ข Secure server-to-server comms
โ€ข Easy regional expansion
One server + client per game server region
โ˜๏ธ Hybrid Cloud Connectivity Connect on-premise infrastructure with cloud resources โ€ข Secure cloud-to-datacenter bridge
โ€ข Automatic path optimization
โ€ข Support for multi-cloud scenarios
One server + client per datacenter/cloud region
๐Ÿ” Zero Trust Network Build a zero-trust network with peer isolation โ€ข Per-peer authentication via identity
โ€ข Fine-grained access control with CIDRs
โ€ข Complete traffic encryption
One server + strict cluster configuration

๐Ÿ› ๏ธ Build from Source

Prerequisites

  • Rust 1.70+: Install Rust
  • Build Tools:
    • Linux: build-essential or equivalent
    • macOS: Xcode Command Line Tools
    • Windows: MSVC Build Tools

Quick Build

# Clone repository
git clone https://github.com/smartethnet/rustun.git
cd rustun

# Build release binaries
cargo build --release

# Binaries will be in target/release/
./target/release/server --help
./target/release/client --help

Cross-Platform Build

# Install cross-compilation tool
cargo install cross

# Build for Linux x86_64 (musl, static)
cross build --release --target x86_64-unknown-linux-musl

# Build for ARM64 Linux
cross build --release --target aarch64-unknown-linux-gnu

# Build for Windows
cross build --release --target x86_64-pc-windows-msvc

# Build for macOS (requires macOS host)
cargo build --release --target x86_64-apple-darwin
cargo build --release --target aarch64-apple-darwin

Build Script

Use the provided build script for multi-platform builds:

# Build for all platforms
./build.sh

# Builds will be in build/ directory
# Archives will be in dist/ directory

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details on:

  • Development setup and workflow
  • Code style and conventions
  • Testing requirements
  • Pull request process
  • Project structure

Quick Start for Contributors:

# Fork, clone and create a branch
git clone https://github.com/YOUR_USERNAME/rustun.git
cd rustun
git checkout -b feature/your-feature

# Make changes and test
cargo test
cargo fmt
cargo clippy

# Commit and push
git commit -m "feat: your feature"
git push origin feature/your-feature

For questions and discussions, visit GitHub Discussions.

๐Ÿ“š Architecture

For detailed protocol and architecture documentation, see:

๐Ÿ—บ๏ธ Roadmap

  • IPv6 P2P support - โœ… Completed (IPv6 direct connection)
  • STUN hole punching - โœ… Completed (NAT traversal for IPv4)
  • Dual-path networking - โœ… Completed (IPv6 + STUN with intelligent failover)
  • Real-time connection monitoring - โœ… Completed (Per-path health status)
  • systemd integration for Linux
  • Dynamic route updates without restart
  • Web-based management dashboard
  • Mobile & Desktopclients(Android/iOS/Windows/MacOS)
  • QUIC protocol support
  • Docker container images
  • Kubernetes operator
  • Auto-update mechanism
  • Windows service support

๐Ÿ™ Acknowledgments

๐Ÿ“ž Contact


Note: This is an experimental project. Use at your own risk in production environments.

About

AI-Driven VPN Tunnels

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published