Manage two VPN connections simultaneously on Linux through (Policy Based Routing).
This tool solves the problem of using a corporate VPN and a personal VPN for bypassing internet restrictions at the same time. Perfect for:
# Clone the repository
git clone https://github.com/maks/dual-vpn-router.git
cd dual-vpn-router
# Install deps
go mod tidy
# Build
go build -o dual-vpn ./cmd
# Install (optional)
sudo cp dual-vpn /usr/local/bin/
sudo chmod +x /usr/local/bin/dual-vpn
# 1. Initialize configuration
sudo dual-vpn init
# 2. Edit configuration to match your VPN setup
sudo nano /etc/dual-vpn/config.yaml
# 3. Connect your VPNs (use your VPN client first!)
# - Corporate VPN connection
# - Global VPN connection
# Make sure BOTH VPNs are connected before proceeding!
# 4. Setup routing
sudo dual-vpn setup
# 5. Check status
dual-vpn status
# 6. Cleanup when done (or disconnect VPNs)
sudo dual-vpn cleanup
sudo dual-vpn status)sudo dual-vpn setupsudo dual-vpn cleanup first
The script creates temporary DNS and routing configurations. If you disconnect VPNs before running cleanup:
Always run cleanup BEFORE disconnecting VPNs!
IMPORTANT: You must manually edit the configuration file with your actual corporate DNS servers, domains, and network ranges. The default configuration contains placeholder values.
Run sudo dual-vpn init to create a default config at /etc/dual-vpn/config.yaml, then edit it:
sudo nano /etc/dual-vpn/config.yaml
dns.domains: Replace with your corporate domain(s)
name: Your corporate domain (e.g., company.internal)servers: Your corporate DNS server IP addressesrouting.corp_networks: Add your corporate network ranges
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16vpns.interface: Check your VPN interface names
ip link show after connecting VPNs to see interface namestun0, wg0, ppp0# ===== YOU MUST CHANGE THESE =====
dns:
listen_addr: 127.0.0.1:53 # OK: Leave as is
fallback:
- 8.8.8.8 # OK: Leave as is (public DNS)
- 8.8.4.4 # OK: Leave as is (public DNS)
domains:
- name: corporate.example.com # CHANGE: Your corporate domain
servers:
- 192.168.1.1 # CHANGE: Your corporate DNS server IP
- 192.168.1.2 # CHANGE: Your corporate DNS server IP (if you have)
routing:
corp_table_id: 200 # OK: Leave as is
corp_networks:
- 10.0.0.0/8 # OK: Keep if your company uses these ranges
- 172.16.0.0/12 # OK: Keep if your company uses these ranges
- 192.168.0.0/16 # OK: Keep if your company uses these ranges
vpns:
- name: corporate # OK: Leave as is
interface: tun0 # CHECK: Run 'ip link show' to verify your interface name
auto_detect: true # OK: Leave as is
type: corporate # OK: Leave as is
- name: global # OK: Leave as is
interface: wg0 # CHECK: Run 'ip link show' to verify your interface name
auto_detect: true # OK: Leave as is
type: global # OK: Leave as is
| Parameter | Description | Example |
|---|---|---|
dns.listen_addr |
Where dnsmasq listens for DNS queries | 127.0.0.1:53 |
dns.fallback |
Default DNS servers for non-corporate domains | 8.8.8.8 |
dns.domains[].name |
Corporate domain name | company.internal |
dns.domains[].servers |
Corporate DNS server IPs | 192.168.1.1 |
routing.corp_table_id |
Routing table ID for corporate traffic | 200 |
routing.corp_networks |
Networks routed through corporate VPN | 10.0.0.0/8 |
vpns[].interface |
VPN interface name | tun0 |
vpns[].type |
VPN type: corporate or global |
corporate |
| Command | Description |
|---|---|
dual-vpn init |
Create default configuration file |
dual-vpn setup |
Set up dual VPN routing (run AFTER VPNs are connected) |
dual-vpn cleanup |
Remove all routing rules and restore DNS (run BEFORE disconnecting VPNs) |
dual-vpn status |
Show current status |
No, the script does NOT manage VPN connections automatically. You must:
dual-vpn setup AFTER both VPNs are connecteddual-vpn cleanup BEFORE disconnecting VPNsThe script only manages DNS and routing configuration, not the VPN connections themselves.
The dual-vpn init command creates a placeholder configuration. You must edit it manually:
sudo dual-vpn init
sudo nano /etc/dual-vpn/config.yaml
Without proper configuration, the routing will not work correctly. Make sure to:
dns.domainsdns.domains[].serversrouting.corp_networksvpns[].interfaceMIT License
Contributions are welcome! Please feel free to submit a Pull Request.
linux, vpn, pbr, policy based routing, dual vpn, split routing, подключить два впн одновременно, два впн на одном компьютере, ip routing, dns routing, настройка двух vpn, split dns, политика маршрутизации, два vpn на linux, корпоративный vpn и личный vpn одновременно