A lightweight, open-source VPN solution built from scratch. OpenTunnel provides secure encrypted tunneling with native clients for all major platforms.
- Full Tunnel VPN: Route all internet traffic through the VPN server
- TLS 1.3 Encryption: Secure communication using modern cryptography
- Multi-Platform Clients: Native apps for macOS, iOS, Android, and Windows
- Docker Deployment: One-command installation using Docker
- PostgreSQL Backend: Reliable user authentication and session management
┌─────────────────────────────────────────────────────────────────┐
│ Clients │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ iOS │ │ Android │ │ macOS │ │ Windows │ │
│ │ Swift │ │ Kotlin │ │ Swift │ │ C# │ │
│ └────┬─────┘ └────┬─────┘ └────┬─────┘ └────┬─────┘ │
│ └─────────────┴─────────────┴─────────────┘ │
│ │ │
│ TLS 1.3 Encrypted Tunnel │
│ (Port 1194) │
└───────────────────────────┼─────────────────────────────────────┘
│
┌───────────────────────────▼─────────────────────────────────────┐
│ VPN Server (Docker) │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ TLS Server │ │ TUN Device │ │ NAT/FW │ │
│ │ (Rust) │ │ (native) │ │ (iptables) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │
│ ┌──────▼──────┐ │
│ │ PostgreSQL │ │
│ └─────────────┘ │
└─────────────────────────────────────────────────────────────────┘
curl -fsSL https://raw.githubusercontent.com/datamaker/opentunnel/main/install.sh | sudo bashThis will:
- Pull the Docker image from Docker Hub
- Create a docker-compose.yml configuration
- Start the VPN server and PostgreSQL database
- Enable IP forwarding on the host
# Create network docker network create vpn-network # Start PostgreSQL docker run -d \ --name opentunnel-db \ --network vpn-network \ -e POSTGRES_USER=vpn \ -e POSTGRES_PASSWORD=your-secure-password \ -e POSTGRES_DB=vpn \ postgres:15-alpine # Start VPN Server docker run -d \ --name opentunnel-vpn \ --network vpn-network \ --cap-add=NET_ADMIN \ --device=/dev/net/tun \ -p 1194:1194 \ -e DB_HOST=opentunnel-db \ -e DB_PASSWORD=your-secure-password \ datamaker/opentunnel:rust # Enable IP forwarding on host sudo sysctl -w net.ipv4.ip_forward=1
# Check containers are running docker ps # View server logs docker logs -f opentunnel-vpn # Test TLS connection openssl s_client -connect localhost:1194 -tls1_3
No VPN users are seeded — earlier versions shipped admin/admin123 and
testuser/test123, i.e. the same known credentials on every install's live
VPN. Instead, provision users from the admin panel: set ADMIN_PASSWORD
(and/or ADMIN_SSO_EMAILS) in your .env, open the panel, and add users under
Users. You can also insert one directly (see Adding Users).
The server address and credentials are entered on the app's login screen at runtime — you do not edit them in source. Prebuilt Android (APK) and Windows installers are attached to each GitHub release; the sections below are for building from source.
SSO (Google device flow) currently has the OIDC issuer and Apple bundle identifiers hardcoded to this project's values. To use SSO in your own deployment you must change those in the client sources; password login works without any edits.
macOS and iOS share one Xcode project (an app target plus a Packet Tunnel
extension); there is no separate clients/ios/ directory.
- Open
clients/macos/VPNClient/VPNClient.xcodeprojin Xcode. - Select your development team for code signing (required for the Network Extension entitlement).
- Build and run the
VPNClientscheme (⌘R). For iOS, choose a physical device — the Packet Tunnel APIs do not work in the Simulator. - Enter the server address and credentials on the login screen and connect. On iOS, approve the VPN profile when prompted.
- Open
clients/android/in Android Studio, or build from the command line:cd clients/android && ./gradlew assembleRelease
- Install the APK and grant the VPN permission when prompted.
- Enter the server address and credentials on the login screen and connect.
- Open
clients/windows/VPNClient.slnin Visual Studio, or build from the command line:The build expectscd clients/windows && dotnet publish VPNClient/VPNClient.csproj -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -o ./publish
wintun.dllnext to the executable (see.github/workflows/build-clients.ymlfor how CI fetches it). - Run as Administrator (required to create the WinTun adapter).
- Enter the server address and credentials and connect.
| Variable | Default | Description |
|---|---|---|
VPN_PORT |
1194 | VPN server port |
VPN_SUBNET |
10.8.0.0 | VPN client subnet |
VPN_NETMASK |
255.255.255.0 | Subnet mask |
DNS_SERVERS |
8.8.8.8,8.8.4.4 | DNS servers for clients |
DB_HOST |
localhost | PostgreSQL host |
DB_PORT |
5432 | PostgreSQL port |
DB_NAME |
vpn | Database name |
DB_USER |
vpn | Database user |
DB_PASSWORD |
required | Database password |
JWT_SECRET |
auto-generated | JWT signing secret |
Connect to the database and insert users:
-- Connect to database docker exec -it opentunnel-db psql -U vpn -- Generate bcrypt hash for password (use bcrypt online tool or node) -- Example: password "mypassword" = "$2b$10$..." INSERT INTO users (username, password_hash, is_active, max_connections) VALUES ('newuser', '$2b$10$your-bcrypt-hash', true, 3);
┌─────────┬──────────────┬─────────────────┐
│ Type │ Length │ Payload │
│ 1 byte │ 4 bytes │ N bytes │
│ │ (big-endian)│ │
└─────────┴──────────────┴─────────────────┘
| Type | Code | Description |
|---|---|---|
| AUTH_REQUEST | 0x01 | Client sends username/password |
| AUTH_RESPONSE | 0x02 | Server responds with success/failure |
| CONFIG_PUSH | 0x03 | Server sends VPN config (IP, DNS, etc.) |
| KEEPALIVE | 0x04 | Keepalive ping |
| KEEPALIVE_ACK | 0x05 | Keepalive acknowledgment |
| DISCONNECT | 0x06 | Graceful disconnect |
| DATA_PACKET | 0x10 | Encapsulated IP packet |
Client Server
│ │
│──── AUTH_REQUEST ────────────────>│
│ {username, password} │
│ │
│<─── AUTH_RESPONSE ────────────────│
│ {success, sessionToken} │
│ │
│<─── CONFIG_PUSH ──────────────────│
│ {assignedIP, gateway, dns} │
│ │
│──── DATA_PACKET ─────────────────>│
│ [IP packets] │
│<─── DATA_PACKET ──────────────────│
│ │
# Check if port is open sudo ufw allow 1194/tcp # or sudo iptables -A INPUT -p tcp --dport 1194 -j ACCEPT # Verify Docker is running docker ps | grep opentunnel
# Enable IP forwarding on host sudo sysctl -w net.ipv4.ip_forward=1 # Make persistent echo "net.ipv4.ip_forward=1" | sudo tee -a /etc/sysctl.conf # Check NAT rules in container docker exec opentunnel-vpn iptables -t nat -L POSTROUTING -n -v
# Check server logs docker logs opentunnel-vpn | grep -i auth # Verify user exists in database docker exec opentunnel-db psql -U vpn -c "SELECT username FROM users;" # Reset user password docker exec opentunnel-db psql -U vpn -c \ "UPDATE users SET password_hash='new-bcrypt-hash' WHERE username='your-user';"
# Ensure TUN module is loaded sudo modprobe tun ls -la /dev/net/tun # Verify container has NET_ADMIN capability docker inspect opentunnel-vpn | grep -A5 CapAdd
# Clone repository git clone https://github.com/datamaker/opentunnel.git cd opentunnel/server-rust # Build (Linux, real kernel TUN) cargo build --release --features tun-device # Run (needs certs at ./certs/server.{crt,key} and a reachable Postgres) LOG_LEVEL=debug DB_HOST=localhost DB_PASSWORD=vpnpassword \ cargo run --release --features tun-device
cd server-rust docker build -t opentunnel:rust . # Test locally docker run --rm -it \ --cap-add=NET_ADMIN \ --device=/dev/net/tun \ -p 1194:1194 \ opentunnel:rust
opentunnel/
├── server-rust/ # Rust VPN server
│ ├── src/
│ │ ├── main.rs # Entry point
│ │ ├── config.rs # Configuration
│ │ ├── tun.rs # Native kernel TUN device
│ │ ├── tls.rs # TLS server (rustls)
│ │ ├── protocol/ # VPN protocol
│ │ ├── routing/ # Packet routing
│ │ ├── session/ # Session management
│ │ ├── split.rs # Split-tunnel policy
│ │ ├── auth.rs # Authentication
│ │ └── db.rs # Database
│ ├── schema.sql # PostgreSQL schema
│ ├── Dockerfile
│ └── Cargo.toml
│
├── clients/
│ ├── android/ # Android client (Kotlin)
│ ├── macos/ # macOS + iOS client (Swift, multiplatform)
│ └── windows/ # Windows client (C#)
│
├── install.sh # One-line installer
├── docker-compose.yml # Docker Compose config
└── README.md
- Change default credentials immediately after installation
- Use strong passwords (16+ characters recommended)
- Keep Docker and host system updated
- Use a firewall to restrict access to management ports
- Monitor logs for suspicious activity
- Consider using fail2ban for brute-force protection
MIT License - see LICENSE for details.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Inspired by OpenVPN architecture
- Built with Rust, Swift, Kotlin, and C#
- Uses PostgreSQL for reliable data storage