跳转到内容

使用场景

常见 rVPN 部署的实用指南。


rVPN 支持两种运行模式:

使用场景推荐模式
按应用代理(浏览器、单个应用)SOCKS5
全设备 VPN(所有流量)TUN
移动端(iOS、Android)TUN(内置)
像在局域网中一样连接到远程网络TUN
分流:部分流量走 VPN,部分直连两者均可搭配 split_tunnel 配置

两种模式均使用相同的 X3DH + Double Ratchet 加密。区别在于流量如何到达 VPN。


从家中连接到工作电脑,就像身处同一办公网络。使用 RDP、VNC、SSH 或任何远程访问工具,无需向公网暴露端口。

  • 暴露到互联网的 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 = true
dhcp_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 = true
routes = ["10.100.0.0/16"] # Your office network subnet
mtu = 1420

这样只有目的地为 10.100.0.0/16(你的办公网络)的流量通过 VPN。其他所有流量(浏览、流媒体)仍走你的正常家庭连接。

3. 验证连通性

Terminal window
# 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 server
ping 10.100.0.50
  • 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

将不同地点的多台服务器连接为一个安全的私有网络。所有服务器和客户端不论物理位置在何处,都表现得如同在同一个局域网中。

  • 无需专线即可连接不同城市的办公室
  • 像在同一网络中一样访问云端 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

每个地点运行一个 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 = true
dhcp_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 = true
dhcp_range = "10.200.0.0/24"
[server.tun]
tun_ip = "10.200.0.1/24"
dns_servers = ["10.200.0.1"]

要同时访问两个子网,客户端需要为两者添加路由:

[tun]
enabled = true
routes = ["10.100.0.0/16", "10.200.0.0/16"] # Covers both office and cloud subnets
mtu = 1420

或者,如果需要全隧道(所有流量走 VPN),只需使用 routes = ["0.0.0.0/0"]

要在所有地点之间使用主机名而非 IP,请配置私有 DNS 服务器:

[server.network]
nat_enabled = true
dhcp_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.10
db02.office.internal 10.200.0.10

远程访问开发服务器、数据库和微服务,就像它们在本地运行一样。适合远程办公或出差。

  • 开发环境位于私有网络,外部无法访问
  • 你需要测试回调 localhost 的 webhook
  • 你想使用本地开发 URL 而不必修改它们

将整个开发网络通过 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 = true
listen_address = "127.0.0.1:53"

将系统 DNS 配置为 127.0.0.1:53。此时 dev.internalcompany.com 能正确解析,且所有开发流量都通过 VPN。

使用 TUN 模式并指定特定路由,避免拖慢整体连接:

[tun]
enabled = true
routes = [
"10.50.0.0/24", # Dev network
"192.168.1.0/24", # Home network (stays direct)
]
mtu = 1420

对直接数据库连接,请使用 SOCKS5 代理:

Terminal window
# MySQL
mysql -h 10.50.0.20 -P 3306 --protocol=TCP
# PostgreSQL
psql -h 10.50.0.21 -p 5432
# MongoDB
mongosh "mongodb://10.50.0.22:27017"

将你的数据库 GUI(DBeaver、TablePlus、DataGrip)配置为通过 127.0.0.1:1080 的 SOCKS5 连接。

如果远程 API 需要回调到你开发服务器上的 localhost:3000,VPN 隧道能让远程 API 到达你的本机:

  1. 你的开发机器以 TUN 模式连接
  2. 远程服务调用你服务器的公网 IP
  3. 服务器将请求通过 VPN 转发到你的开发机器
  4. 你的本地服务通过隧道响应

将 AWS、GCP、Azure 或其他云提供商的服务器连接为一个私有网络,无需使用云提供商的 VPN 或向公网暴露服务。

  • 跨云数据库无需公共端点
  • 不同云区域间服务的私有通信
  • 无需云提供商特定的 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

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 routing
dhcp_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 = false
dhcp_range = "10.1.0.0/24"
[server.tun]
tun_ip = "10.1.0.1/24"
dns_servers = ["10.1.0.53"]

每个云提供商的防火墙必须允许:

  • 来自 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 = true
routes = ["10.0.0.0/8"] # All private cloud ranges
mtu = 1420
  • 跨云数据库复制:10.0.0.30:3306 的 MySQL 到 10.1.0.30:5432 的 PostgreSQL
  • 私有容器注册中心:无论在哪运行,registry.internal:5000
  • 内部 API:api.internal:8080,无需公共端点
  • 备份复制:服务器间的 rsync,无需经过公网

分流让你决定哪些流量通过 VPN,哪些走正常的互联网连接。

适合使用分流的场景:

场景配置
流媒体服务(Netflix、Spotify)绕过国家或特定 IP
游戏绕过游戏服务器 IP 以降低延迟
本地网络设备绕过家庭/办公局域网子网
银行应用视安全策略绕过或走隧道
开发服务器只将开发网络走隧道

避免使用分流的场景:

场景建议
不可信的公共 Wi-Fi全隧道
访问敏感账户全隧道
绕过工作场所内容过滤全隧道(可能违反政策)
Outgoing packet → Check bypass rules →
→ Matches bypass? → Send directly (no encryption)
→ No match? → Send through VPN tunnel

绕过在加密之前进行判断。命中的流量绝不会进入 VPN 隧道。

[split_tunnel]
enabled = true
builtin_bypass_countries = ["CN", "HK", "SG", "JP", "KR", "TW"]

这会绕过前往注册在这些国家 IP 地址的流量。适用场景:

  • 你出国旅行,希望访问国内内容而不减速
  • 屏蔽外国 IP 的流媒体服务

限制:国家绕过使用 APNIC IP 范围数据。大型 CDN 可能从多个国家的 IP 提供内容。

无论国家,绕过特定 IP 范围:

[split_tunnel]
enabled = true
bypass_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 和其他私有子网

绕过前往特定域名的流量:

[split_tunnel]
enabled = true
bypass_domains_file = "~/.config/rvpn/bypass-domains.txt"

bypass-domains.txt

netflix.com
spotify.com
hulu.com
disneyplus.com

基于域名的绕过使用 DNS 解析:域名在本地解析(不经 VPN),得到的 IP 绕过隧道。

即便某些域名本应绕过,也强制通过 VPN:

[split_tunnel]
enabled = true
tunnel_domains_file = "~/.config/rvpn/tunnel-domains.txt"

适用场景:

  • 你的 ISP 对特定服务限速
  • 你想为隐私强制流媒体走 VPN
[split_tunnel]
enabled = true
block_ads = true

在 DNS 层拦截已知广告和跟踪域名。被拦截的域名立即返回 NXDOMAIN。与绕过规则协同工作:绕过的域名会在本地解析,且不进行广告拦截。

规则按此顺序求值:

  1. tunnel_networks / tunnel_domains(强制通过 VPN)
  2. bypass_networks / bypass_domains / builtin_bypass_countries(强制直连)
  3. 默认(TUN 模式下全隧道,SOCKS5 模式下走代理)
Terminal window
# Check your exit IP (should be VPN server if tunneled)
curl https://api.ipify.org
# Check a specific IP
curl --socks5 127.0.0.1:1080 https://api.ipify.org
# Test DNS resolution through tunnel
dig @127.0.0.1 example.com
# Trace routing
traceroute 8.8.8.8

何时使用全隧道(不使用分流):

[split_tunnel]
enabled = false
  • 在不可信的公共网络上(咖啡厅、酒店、机场 Wi-Fi)
  • 需要最大隐私时
  • 绕过规则可能意外排除敏感流量时

分流的风险:

绕过 VPN 的流量对你的 ISP 和本地网络运营者可见。如果你绕过了银行站点,你的 ISP 就能看到你访问了它们。请评估这是否符合你的威胁模型。

国家绕过的风险:

流媒体服务可能通过其他方式(支付货币、账户历史、GPS 位置)检测 VPN 使用。国家绕过会让流量看起来是国内的,但不会改变这些其他信号。