开源VPN实战(四):Pritunl 多云站点到站点互联

作者:

系列文章回顾

这是「开源VPN实战」系列的第四篇。前三篇我们介绍了 Pritunl 的安装部署、安全加固和 SSO 集成,本篇将深入讲解如何使用 Pritunl Link 实现多云环境的站点到站点互联。

系列文章

  • 第一篇:Pritunl 入门与安装配置
  • 第二篇:安全功能详解
  • 第三篇:SSO单点登录企业集成
  • 第四篇:多云站点到站点互联(本文)
  • 第五篇:高可用与运维实战

为什么需要站点到站点互联?

在企业多云架构中,不同云平台、不同区域的网络需要互通:

  • 多云部署:AWS、Azure、Google Cloud 混合使用
  • 多区域部署:同一云商的不同区域
  • 混合云:云上与 IDC 机房互联
  • 分支机构:总部与分支机构网络互通

Pritunl Link 架构

核心组件

Pritunl Link 客户端

  • 部署在每个需要互联的网络中
  • 通过 HTTPS 与 Pritunl 集群通信
  • 自动建立 IPsec 隧道
  • 支持自动故障转移

Pritunl 服务器集群

  • 管理所有 Link 客户端
  • 下发配置和路由
  • 监控连接状态

工作原理

  1. 配置管理:在 Pritunl Web 控制台配置 Link 和路由
  2. 客户端注册:Link 客户端通过 URI 注册到集群
  3. 隧道建立:客户端之间自动建立 IPsec 隧道
  4. 路由同步:自动同步路由表到云平台

关键特性

  • 自动故障转移:每个站点可部署多个客户端
  • 自动路由:支持 AWS、Google Cloud、Ubiquiti 路由表自动更新
  • 高性能加密:支持 AES-128-GCM、ChaCha20 等现代加密算法
  • 主机检查:检测网络分区,选择最佳激活链路

配置前准备

1. 安装 Pritunl Link 客户端

在每个需要互联的网络中安装 pritunl-link:

`bash

# AlmaLinux/Rocky Linux

sudo tee /etc/yum.repos.d/pritunl.repo << EOF

[pritunl]

name=Pritunl Repository

baseurl=https://repo.pritunl.com/stable/yum/almalinux/9/

gpgcheck=1

enabled=1

gpgkey=https://raw.githubusercontent.com/pritunl/pgp/master/pritunl_repo_pub.asc

EOF

sudo dnf -y install pritunl-link

sudo systemctl enable pritunl-link

`

`bash

# Ubuntu 24.04

sudo tee /etc/apt/sources.list.d/pritunl.list << EOF

deb [ signed-by=/usr/share/keyrings/pritunl.gpg ] https://repo.pritunl.com/stable/apt noble main

EOF

curl -fsSL https://raw.githubusercontent.com/pritunl/pgp/master/pritunl_repo_pub.asc | sudo gpg -o /usr/share/keyrings/pritunl.gpg –dearmor –yes

sudo apt update

sudo apt -y install pritunl-link

sudo systemctl enable pritunl-link

`

2. 创建 Link 配置

在 Pritunl Web 控制台:

  1. 导航到 Link 页面
  2. 点击 “Add Link”
  3. 为每个网络创建 Location
  4. 为每个 Location 添加路由(子网)

3. 添加 Host

  1. 点击 “Add Host”
  2. 记录生成的 URI
  3. 在 Link 客户端上执行 URI

4. 推荐加密算法

`bash

# AES 128 GCM(推荐,性能最佳)

IKE=aes128-sha256-x25519 ESP=aes128gcm128-x25519

# AES 256 GCM(更高安全性)

IKE=aes256-sha256-x25519 ESP=aes256gcm128-x25519

# ChaCha20(无 AES 硬件加速时推荐)

IKE=chacha20poly1305-prfsha256-x25519 ESP=chacha20poly1305-x25519

`

在服务器设置中启用 “Force Preferred Cipher” 强制使用推荐算法。

AWS 站点到站点配置

场景示例

假设有两个 VPC 需要互联:

  • VPC-A10.0.0.0/16(us-east-1)
  • VPC-B10.1.0.0/16(us-west-2)

步骤 1:创建 IAM 角色

创建具有 VPC 路由表修改权限的 IAM 角色:

`json

{

“Version”: “2012-10-17”,

“Statement”: [

{

“Effect”: “Allow”,

“Action”: [

“ec2:DescribeRouteTables”,

“ec2:CreateRoute”,

“ec2:ReplaceRoute”,

“ec2:DeleteRoute”

],

“Resource”: “*”

}

]

}

`

步骤 2:创建安全组

开放以下端口:

  • UDP 500:IKE
  • UDP 4500:IPsec NAT-T
  • TCP 9790:主机检查(可选)

步骤 3:启动 Link 客户端实例

在 VPC-A 中启动 Amazon Linux 2023 实例:

  1. 选择创建的 IAM 角色
  2. 配置 User Data 启动脚本

`bash

#!/bin/bash

# 禁用 SSL 证书验证(如果 Pritunl 使用自签名证书)

sudo pritunl-link verify-off

# 设置云提供商

sudo pritunl-link set-provider aws

# 添加 Link URI(从 Pritunl Web 控制台获取)

sudo pritunl-link add-uri PRLINK_URI

`

步骤 4:验证连接

`bash

# 检查 pritunl-link 状态

sudo systemctl status pritunl-link

# 查看日志

sudo journalctl -u pritunl-link -f

# 验证路由表更新

aws ec2 describe-route-tables –filters “Name=vpc-id,Values=vpc-xxxxxxxx”

`

步骤 5:测试连通性

从 VPC-A 的实例 ping VPC-B 的实例:

`bash

# 假设 VPC-B 中有实例 10.1.0.100

ping 10.1.0.100

`

Azure 站点到站点配置

场景示例

  • Azure VNet-A10.0.0.0/16(East US)
  • AWS VPC-B10.1.0.0/16(us-west-2)

步骤 1:创建 Azure 虚拟机

  1. 创建 Ubuntu 22.04 虚拟机
  2. 配置网络安全组(NSG)

步骤 2:配置网络安全组

开放端口:

  • UDP 500
  • UDP 4500
  • TCP 9790(可选)

步骤 3:启用 IP 转发

在 Azure 门户:

  1. 导航到虚拟机 > 网络
  2. 选择网络接口
  3. 启用 IP 转发

或使用 Azure CLI:

`bash

az network nic update

–resource-group myResourceGroup

–name myNic

–ip-forwarding true

`

步骤 4:配置路由表

`bash

# 创建路由表

az network route-table create

–resource-group myResourceGroup

–name myRouteTable

# 添加到 AWS VPC 的路由

az network route-table route create

–resource-group myResourceGroup

–route-table-name myRouteTable

–name route-to-aws

–address-prefix 10.1.0.0/16

–next-hop-type VirtualAppliance

–next-hop-ip-address 10.0.0.100

# 关联到子网

az network vnet subnet update

–resource-group myResourceGroup

–vnet-name myVNet

–name mySubnet

–route-table myRouteTable

`

步骤 5:安装并配置 Link

`bash

# 安装 pritunl-link

sudo apt update

sudo apt -y install pritunl-link

# 禁用 SSL 验证

sudo pritunl-link verify-off

# 设置提供商

sudo pritunl-link set-provider azure

# 添加 Link URI

sudo pritunl-link add-uri PRLINK_URI

`

Google Cloud 站点到站点配置

场景示例

  • GCP VPC-A10.0.0.0/16(us-central1)
  • AWS VPC-B10.1.0.0/16(us-west-2)

步骤 1:创建防火墙规则

`bash

# 允许 IPsec 流量

gcloud compute firewall-rules create allow-ipsec

–network my-vpc

–allow udp:500,udp:4500

–source-ranges 0.0.0.0/0

# 允许主机检查(可选)

gcloud compute firewall-rules create allow-link-check

–network my-vpc

–allow tcp:9790

–source-ranges 10.0.0.0/8

`

步骤 2:创建实例并启用 IP 转发

`bash

# 创建实例时启用 IP 转发

gcloud compute instances create link-client

–zone us-central1-a

–machine-type e2-medium

–image-family ubuntu-2204-lts

–image-project ubuntu-os-cloud

–can-ip-forward

–network my-vpc

–subnet my-subnet

`

步骤 3:配置路由

`bash

# 创建路由到 AWS VPC

gcloud compute routes create route-to-aws

–network my-vpc

–destination-range 10.1.0.0/16

–next-hop-instance link-client

–next-hop-instance-zone us-central1-a

`

步骤 4:安装并配置 Link

`bash

# SSH 到实例

gcloud compute ssh link-client –zone us-central1-a

# 安装 pritunl-link

sudo apt update

sudo apt -y install pritunl-link

# 禁用 SSL 验证

sudo pritunl-link verify-off

# 设置提供商

sudo pritunl-link set-provider google

# 添加 Link URI

sudo pritunl-link add-uri PRLINK_URI

`

Oracle Cloud 站点到站点配置

场景示例

  • OCI VCN-A10.0.0.0/16(us-phoenix-1)
  • AWS VPC-B10.1.0.0/16(us-west-2)

步骤 1:配置安全列表

在 OCI 控制台:

  1. 导航到 Networking > Virtual Cloud Networks
  2. 选择 VCN > Security Lists
  3. 添加 Ingress Rules:
  • UDP 500:源 0.0.0.0/0
  • UDP 4500:源 0.0.0.0/0

步骤 2:创建实例

  1. 创建 Ubuntu 22.04 实例
  2. 分配公网 IP
  3. 配置 VNIC 以启用源/目标检查禁用

`bash

# 禁用 VNIC 源/目标检查

oci network vnic update

–vnic-id ocid1.vnic.oc1…

–skip-source-dest-check true

`

步骤 3:配置路由

`bash

# 创建路由表

oci network route-table create

–compartment-id ocid1.compartment.oc1…

–vcn-id ocid1.vcn.oc1…

–route-rules ‘[{

“destination”: “10.1.0.0/16”,

“destinationType”: “CIDR_BLOCK”,

“networkEntityId”: “ocid1.privateip.oc1…”

}]’

# 关联到子网

oci network subnet update

–subnet-id ocid1.subnet.oc1…

–route-table-id ocid1.routetable.oc1…

`

步骤 4:安装并配置 Link

`bash

# SSH 到实例

ssh -i key.pem ubuntu@

# 安装 pritunl-link

sudo apt update

sudo apt -y install pritunl-link

# 禁用 SSL 验证

sudo pritunl-link verify-off

# 设置提供商

sudo pritunl-link set-provider oracle

# 添加 Link URI

sudo pritunl-link add-uri PRLINK_URI

`

Ubiquiti EdgeRouter 配置

适用场景

将 Ubiquiti EdgeRouter 防火墙连接到云上 Pritunl Link。

配置步骤

  1. 获取 Pritunl Link URI
  2. 登录 EdgeRouter CLI
  3. 安装 pritunl-link

`bash

# 进入配置模式

configure

# 配置 IPsec

set vpn ipsec esp-group Pritunl compression ‘disable’

set vpn ipsec esp-group Pritunl lifetime ‘3600’

set vpn ipsec esp-group Pritunl mode ‘tunnel’

set vpn ipsec esp-group Pritunl pfs ‘enable’

set vpn ipsec esp-group Pritunl proposal 1 encryption ‘aes128gcm128’

set vpn ipsec esp-group Pritunl proposal 1 hash ‘sha256’

set vpn ipsec ike-group Pritunl ikev2-reauth ‘no’

set vpn ipsec ike-group Pritunl key-exchange ‘ikev2’

set vpn ipsec ike-group Pritunl lifetime ‘28800’

set vpn ipsec ike-group Pritunl proposal 1 dh-group ’25’

set vpn ipsec ike-group Pritunl proposal 1 encryption ‘aes128’

set vpn ipsec ike-group Pritunl proposal 1 hash ‘sha256’

# 配置 site-to-site peer

set vpn ipsec site-to-site peer authentication id ”

set vpn ipsec site-to-site peer authentication mode ‘pre-shared-secret’

set vpn ipsec site-to-site peer authentication pre-shared-secret ”

set vpn ipsec site-to-site peer connection-type ‘initiate’

set vpn ipsec site-to-site peer ike-group ‘Pritunl’

set vpn ipsec site-to-site peer local-address ”

# 添加隧道

set vpn ipsec site-to-site peer tunnel 1 allow-nat-networks ‘disable’

set vpn ipsec site-to-site peer tunnel 1 allow-public-networks ‘disable’

set vpn ipsec site-to-site peer tunnel 1 esp-group ‘Pritunl’

set vpn ipsec site-to-site peer tunnel 1 local prefix ‘10.0.0.0/16’

set vpn ipsec site-to-site peer tunnel 1 remote prefix ‘10.1.0.0/16’

# 提交并保存

commit

save

`

高级配置

主机检查

主机检查用于检测网络分区和选择最佳激活链路:

`bash

# 在所有 Link 客户端上

# 确保 TCP 端口 9790 可访问

# 检查主机检查状态

sudo pritunl-link status

`

自动防火墙

自动配置 iptables 仅允许其他 Link 主机访问 IPsec 端口:

`bash

# 启用自动防火墙

sudo pritunl-link firewall-on

# 外部防火墙仍需开放 UDP 500/4500

# 但 iptables 会进一步限制源 IP

`

路由移除

默认不自动移除路由,可手动启用:

`bash

# 启用自动路由移除

sudo pritunl-link remove-routes-on

`

主机优先级

在 Web 控制台设置主机优先级:

  • 优先级高的主机优先使用
  • 用于故障转移场景
  • 用于非对称网络拓扑

主机超时

配置故障转移超时:

  • 默认 30 秒
  • 故障转移时间 ≈ 3 秒 + 超时时间
  • 较低超时 = 更快故障转移,但可能误触发

性能优化

加密算法选择

算法 性能 安全性 推荐场景

|——|——|——–|———-|

AES-128-GCM ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ 默认推荐
AES-256-GCM ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ 高安全需求
ChaCha20 ⭐⭐⭐⭐ ⭐⭐⭐⭐ 无 AES 硬件

硬件加速

支持 Mellanox ConnectX-6 DX 等网卡的硬件卸载:

  • 单连接:12.8 Gbit/sec
  • 10 连接:13.2 Gbit/sec

MTU 优化

`bash

# 检查路径 MTU

ping -M do -s 1400

# 调整 Link MTU(如需要)

sudo pritunl-link set-mtu 1400

`

故障排除

Q1: Link 状态显示离线

检查

  1. 防火墙是否开放 UDP 500/4500
  2. Link 客户端是否正常运行
  3. URI 是否正确

诊断

`bash

sudo systemctl status pritunl-link

sudo journalctl -u pritunl-link -f

`

Q2: 路由未自动更新

检查

  1. IAM 角色权限是否正确
  2. 云提供商是否配置正确
  3. 路由表是否可写

Q3: 网络不通

检查

  1. 安全组/防火墙规则
  2. 路由表配置
  3. 子网关联

诊断

`bash

# 检查路由

ip route show

# 检查 IPsec 状态

sudo ipsec status

# 检查连接

sudo ipsec statusall

`

Q4: 故障转移不工作

检查

  1. 主机检查端口 9790 是否开放
  2. 主机优先级配置
  3. 超时设置

最佳实践

1. 高可用设计

  • 每个站点部署 2+ Link 客户端
  • 配置不同的优先级
  • 启用主机检查

2. 安全建议

  • 使用推荐的加密算法
  • 启用自动防火墙
  • 限制路由范围

3. 监控建议

  • 监控 Link 状态
  • 设置连接告警
  • 记录审计日志

4. 性能建议

  • 选择合适的加密算法
  • 启用硬件加速(如可用)
  • 优化 MTU 设置

混合云互联方案

方案 1:AWS + Azure + Google Cloud

`

AWS VPC (10.0.0.0/16)

↕ Pritunl Link

Azure VNet (10.1.0.0/16)

↕ Pritunl Link

Google Cloud VPC (10.2.0.0/16)

`

方案 2:云上 + IDC

`

AWS VPC (10.0.0.0/16)

↕ Pritunl Link

IDC (192.168.0.0/16)

  • EdgeRouter/Firewall
  • pritunl-link

`

方案 3:多区域部署

`

AWS us-east-1 (10.0.0.0/16)

↕ Pritunl Link

AWS us-west-2 (10.1.0.0/16)

↕ Pritunl Link

AWS eu-west-1 (10.2.0.0/16)

`

下一篇预告

第五篇:高可用与运维实战

将详细介绍:

  • MongoDB 副本集配置
  • Pritunl 集群部署
  • 监控与告警(InfluxDB + Grafana)
  • 备份与恢复
  • 性能调优
  • 插件开发
  • API 使用

相关资源

  • Link 文档:https://docs.pritunl.com/kb/vpn/link
  • AWS 教程:https://docs.pritunl.com/kb/vpn/tutorials/pritunl-link
  • IPsec 规格:https://wiki.strongswan.org/projects/strongswan/wiki/IKEv2CipherSuites

*本文基于 Pritunl 官方文档整理,更多技术细节请访问官方文档。*

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注