使用场景
常见 rVPN 部署的实用指南。
选择你的模式
Section titled “选择你的模式”rVPN 支持两种运行模式:
| 使用场景 | 推荐模式 |
|---|---|
| 按应用代理(浏览器、单个应用) | SOCKS5 |
| 全设备 VPN(所有流量) | TUN |
| 移动端(iOS、Android) | TUN(内置) |
| 像在局域网中一样连接到远程网络 | TUN |
| 分流:部分流量走 VPN,部分直连 | 两者均可搭配 split_tunnel 配置 |
两种模式均使用相同的 X3DH + Double Ratchet 加密。区别在于流量如何到达 VPN。
远程桌面访问
Section titled “远程桌面访问”从家中连接到工作电脑,就像身处同一办公网络。使用 RDP、VNC、SSH 或任何远程访问工具,无需向公网暴露端口。
它解决了什么
Section titled “它解决了什么”- 暴露到互联网的 RDP/VNC 是常见的攻击面
- 企业防火墙常常屏蔽 RDP 端口
- 你想访问办公室的打印机、文件共享和内部工具
1. 服务器配置
服务器必须位于办公网络中,并启用 TUN 模式和 NAT 配置:
[server]bind_address = "0.0.0.0:443"tls_cert_file = "/etc/letsencrypt/live/your-office-server.com/fullchain.pem"tls_key_file = "/etc/letsencrypt/live/your-office-server.com/privkey.pem"identity_key_file = "/etc/rvpn/server_identity.key"websocket_path = "/api/v1/ws"
[server.network]nat_enabled = truedhcp_range = "10.200.0.0/24"
[server.tun]tun_ip = "10.200.0.1/24"dns_servers = ["1.1.1.1", "8.8.8.8"]2. 客户端配置
只将办公网络子网通过 VPN 路由。不要路由所有流量:
server_address = "wss://your-office-server.com/api/v1/ws"identity_key_file = "~/.config/rvpn/identity.key"prekey_bundle = "~/.config/rvpn/prekey-bundle.json"
[tun]enabled = trueroutes = ["10.100.0.0/16"] # Your office network subnetmtu = 1420这样只有目的地为 10.100.0.0/16(你的办公网络)的流量通过 VPN。其他所有流量(浏览、流媒体)仍走你的正常家庭连接。
3. 验证连通性
# Force curl through the TUN interface (tun0 on macOS/Linux, utun# on iOS)curl --interface tun0 https://ifconfig.me
# Should return an office network IP (your VPN tunnel IP)# If routing works, regular curl should also work without --interface
# Should reach an office serverping 10.100.0.50隧道能提供什么
Section titled “隧道能提供什么”- RDP:
10.100.0.50:3389 - VNC:
10.100.0.51:5900 - SSH:
ssh [email protected] - SMB 文件共享:
\\10.100.0.53\share - 内部 Web 应用:
http://10.100.0.54:8080
私有网络互联
Section titled “私有网络互联”将不同地点的多台服务器连接为一个安全的私有网络。所有服务器和客户端不论物理位置在何处,都表现得如同在同一个局域网中。
它解决了什么
Section titled “它解决了什么”- 无需专线即可连接不同城市的办公室
- 像在同一网络中一样访问云端 VM
- 运行需要局域网级别网络发现的集群软件
Office A (10.100.0.0/24) Cloud Region (10.200.0.0/24) | | rvpn-server-TUN rvpn-server-TUN (10.100.0.1) (10.200.0.1) \ / \ / \---------------------------/ | rvpn clients get IPs in their respective DHCP ranges and can reach all subnets服务器设置(每个地点)
Section titled “服务器设置(每个地点)”每个地点运行一个 TUN 模式的 rvpn-server。每个站点的 dhcp_range 必须不同:
Office A server.toml:
[server]bind_address = "0.0.0.0:443"tls_cert_file = "/etc/letsencrypt/live/office-a.example.com/fullchain.pem"tls_key_file = "/etc/letsencrypt/live/office-a.example.com/privkey.pem"identity_key_file = "/etc/rvpn/server_identity_office_a.key"websocket_path = "/api/v1/ws"
[server.network]nat_enabled = truedhcp_range = "10.100.0.0/24"
[server.tun]tun_ip = "10.100.0.1/24"dns_servers = ["10.100.0.1"]Cloud region server.toml:
[server.network]nat_enabled = truedhcp_range = "10.200.0.0/24"
[server.tun]tun_ip = "10.200.0.1/24"dns_servers = ["10.200.0.1"]用于多子网访问的客户端路由
Section titled “用于多子网访问的客户端路由”要同时访问两个子网,客户端需要为两者添加路由:
[tun]enabled = trueroutes = ["10.100.0.0/16", "10.200.0.0/16"] # Covers both office and cloud subnetsmtu = 1420或者,如果需要全隧道(所有流量走 VPN),只需使用 routes = ["0.0.0.0/0"]。
用于名称解析的私有 DNS
Section titled “用于名称解析的私有 DNS”要在所有地点之间使用主机名而非 IP,请配置私有 DNS 服务器:
[server.network]nat_enabled = truedhcp_range = "10.100.0.0/24"
[server.tun]tun_ip = "10.100.0.1/24"dns_servers = ["10.100.0.1"]将你的私有 DNS 指向 10.100.0.1。添加主机条目:
db01.office.internal 10.100.0.10db02.office.internal 10.200.0.10远程访问开发服务器、数据库和微服务,就像它们在本地运行一样。适合远程办公或出差。
它解决了什么
Section titled “它解决了什么”- 开发环境位于私有网络,外部无法访问
- 你需要测试回调 localhost 的 webhook
- 你想使用本地开发 URL 而不必修改它们
场景 1:访问所有开发服务
Section titled “场景 1:访问所有开发服务”将整个开发网络通过 VPN 路由:
server_address = "wss://your-dev-server.com/api/v1/ws"identity_key_file = "~/.config/rvpn/identity.key"prekey_bundle = "~/.config/rvpn/prekey-bundle.json"
[socks5]listen_address = "127.0.0.1:1080"
[dns_proxy]enabled = truelisten_address = "127.0.0.1:53"将系统 DNS 配置为 127.0.0.1:53。此时 dev.internalcompany.com 能正确解析,且所有开发流量都通过 VPN。
场景 2:仅访问特定开发服务
Section titled “场景 2:仅访问特定开发服务”使用 TUN 模式并指定特定路由,避免拖慢整体连接:
[tun]enabled = trueroutes = [ "10.50.0.0/24", # Dev network "192.168.1.0/24", # Home network (stays direct)]mtu = 1420对直接数据库连接,请使用 SOCKS5 代理:
# MySQLmysql -h 10.50.0.20 -P 3306 --protocol=TCP
# PostgreSQLpsql -h 10.50.0.21 -p 5432
# MongoDBmongosh "mongodb://10.50.0.22:27017"将你的数据库 GUI(DBeaver、TablePlus、DataGrip)配置为通过 127.0.0.1:1080 的 SOCKS5 连接。
使用 webhook 的本地开发
Section titled “使用 webhook 的本地开发”如果远程 API 需要回调到你开发服务器上的 localhost:3000,VPN 隧道能让远程 API 到达你的本机:
- 你的开发机器以 TUN 模式连接
- 远程服务调用你服务器的公网 IP
- 服务器将请求通过 VPN 转发到你的开发机器
- 你的本地服务通过隧道响应
将 AWS、GCP、Azure 或其他云提供商的服务器连接为一个私有网络,无需使用云提供商的 VPN 或向公网暴露服务。
它解决了什么
Section titled “它解决了什么”- 跨云数据库无需公共端点
- 不同云区域间服务的私有通信
- 无需云提供商特定的 VPN 方案
- 与云提供商无关的一致网络拓扑
AWS us-east-1 (10.0.0.0/24) GCP europe-west1 (10.1.0.0/24) | | rvpn-server-TUN rvpn-server-TUN (10.0.0.1) (10.1.0.1) | | +-------- rvpn tunnel --------+ | Clients get IPs in respective DHCP ranges and can reach all subnets每个云的服务器配置
Section titled “每个云的服务器配置”AWS server.toml:
[server]bind_address = "0.0.0.0:443"tls_cert_file = "/etc/rvpn/certs/cert.pem"tls_key_file = "/etc/rvpn/certs/key.pem"identity_key_file = "/etc/rvpn/server_identity.key"websocket_path = "/api/v1/ws"
[server.network]nat_enabled = false # NAT disabled - we want direct routingdhcp_range = "10.0.0.0/24"
[server.tun]tun_ip = "10.0.0.1/24"dns_servers = ["10.0.0.53"]GCP server.toml:
[server.network]nat_enabled = falsedhcp_range = "10.1.0.0/24"
[server.tun]tun_ip = "10.1.0.1/24"dns_servers = ["10.1.0.53"]安全组和防火墙
Section titled “安全组和防火墙”每个云提供商的防火墙必须允许:
- 来自 VPN 隧道 IP 范围的入站 TCP 443 端口
- 对于跨地点通信,允许其他地点的 VPN IP 范围
以 AWS 安全组为例:
Inbound: TCP 443 from 10.0.0.0/16 (VPN IP range)Inbound: TCP 443 from 10.1.0.0/16 (Other cloud VPN range)[tun]enabled = trueroutes = ["10.0.0.0/8"] # All private cloud rangesmtu = 1420可实现的用例
Section titled “可实现的用例”- 跨云数据库复制:
10.0.0.30:3306的 MySQL 到10.1.0.30:5432的 PostgreSQL - 私有容器注册中心:无论在哪运行,
registry.internal:5000 - 内部 API:
api.internal:8080,无需公共端点 - 备份复制:服务器间的 rsync,无需经过公网
分流让你决定哪些流量通过 VPN,哪些走正常的互联网连接。
何时使用分流
Section titled “何时使用分流”适合使用分流的场景:
| 场景 | 配置 |
|---|---|
| 流媒体服务(Netflix、Spotify) | 绕过国家或特定 IP |
| 游戏 | 绕过游戏服务器 IP 以降低延迟 |
| 本地网络设备 | 绕过家庭/办公局域网子网 |
| 银行应用 | 视安全策略绕过或走隧道 |
| 开发服务器 | 只将开发网络走隧道 |
避免使用分流的场景:
| 场景 | 建议 |
|---|---|
| 不可信的公共 Wi-Fi | 全隧道 |
| 访问敏感账户 | 全隧道 |
| 绕过工作场所内容过滤 | 全隧道(可能违反政策) |
理解绕过逻辑
Section titled “理解绕过逻辑”Outgoing packet → Check bypass rules → → Matches bypass? → Send directly (no encryption) → No match? → Send through VPN tunnel绕过在加密之前进行判断。命中的流量绝不会进入 VPN 隧道。
[split_tunnel]enabled = truebuiltin_bypass_countries = ["CN", "HK", "SG", "JP", "KR", "TW"]这会绕过前往注册在这些国家 IP 地址的流量。适用场景:
- 你出国旅行,希望访问国内内容而不减速
- 屏蔽外国 IP 的流媒体服务
限制:国家绕过使用 APNIC IP 范围数据。大型 CDN 可能从多个国家的 IP 提供内容。
网络绕过(CIDR)
Section titled “网络绕过(CIDR)”无论国家,绕过特定 IP 范围:
[split_tunnel]enabled = truebypass_networks = ["192.168.0.0/16", "10.0.0.0/8", "172.16.0.0/12"]典型绕过网络:
192.168.0.0/16- 家庭/办公局域网10.0.0.0/8- 私有网络172.16.0.0/12- Docker、VPN 和其他私有子网
基于域名的绕过
Section titled “基于域名的绕过”绕过前往特定域名的流量:
[split_tunnel]enabled = truebypass_domains_file = "~/.config/rvpn/bypass-domains.txt"bypass-domains.txt:
netflix.comspotify.comhulu.comdisneyplus.com基于域名的绕过使用 DNS 解析:域名在本地解析(不经 VPN),得到的 IP 绕过隧道。
基于域名的强制隧道
Section titled “基于域名的强制隧道”即便某些域名本应绕过,也强制通过 VPN:
[split_tunnel]enabled = truetunnel_domains_file = "~/.config/rvpn/tunnel-domains.txt"适用场景:
- 你的 ISP 对特定服务限速
- 你想为隐私强制流媒体走 VPN
[split_tunnel]enabled = trueblock_ads = true在 DNS 层拦截已知广告和跟踪域名。被拦截的域名立即返回 NXDOMAIN。与绕过规则协同工作:绕过的域名会在本地解析,且不进行广告拦截。
规则按此顺序求值:
tunnel_networks/tunnel_domains(强制通过 VPN)bypass_networks/bypass_domains/builtin_bypass_countries(强制直连)- 默认(TUN 模式下全隧道,SOCKS5 模式下走代理)
测试分流配置
Section titled “测试分流配置”# Check your exit IP (should be VPN server if tunneled)curl https://api.ipify.org
# Check a specific IPcurl --socks5 127.0.0.1:1080 https://api.ipify.org
# Test DNS resolution through tunneldig @127.0.0.1 example.com
# Trace routingtraceroute 8.8.8.8何时使用全隧道(不使用分流):
[split_tunnel]enabled = false- 在不可信的公共网络上(咖啡厅、酒店、机场 Wi-Fi)
- 需要最大隐私时
- 绕过规则可能意外排除敏感流量时
分流的风险:
绕过 VPN 的流量对你的 ISP 和本地网络运营者可见。如果你绕过了银行站点,你的 ISP 就能看到你访问了它们。请评估这是否符合你的威胁模型。
国家绕过的风险:
流媒体服务可能通过其他方式(支付货币、账户历史、GPS 位置)检测 VPN 使用。国家绕过会让流量看起来是国内的,但不会改变这些其他信号。