跳转到内容
本站为社区维护的非官方中文翻译,与 Cloudflare, Inc. 无关联。本站不提供账户登录,请勿在任何非官方站点输入您的 Cloudflare 账户信息。官方文档:developers.cloudflare.com

Microsoft Azure VPN 网关

最后更新 查看 MarkdownAgent 设置

本教程提供了关于如何使用 Azure 虚拟网络网关 (Virtual Network Gateway) 将 Cloudflare WAN(前称 Magic WAN)连接到您的 Azure 虚拟网络的信息。

前提条件

您需要在您的 Azure 账户中已创建资源组、虚拟网络和虚拟机。请参阅 Microsoft 文档 ↗以了解有关如何创建这些资源的更多信息。

配置 Azure 虚拟网络网关

1. 创建网关子网 (Gateway subnet)

您应该已经创建了一个虚拟网络 (VNET) 并为其分配了子网。下一步是创建一个网关子网,Azure 将使用它来为与 Azure 虚拟网络网关相关的服务进行寻址。如果您已经有了网关子网,Azure 将阻止您创建第二个。如果是这种情况,请更新您的网关子网设置。

  1. 转到您的虚拟网络 > Subnets(子网)。
  2. 选择添加 Gateway subnet 的选项。
  3. 配置子网地址范围。网关子网必须包含在虚拟网络的地址空间内,且其子网掩码须为 /27 或更大。
  4. 确保所有其他设置都设置为 None(无)。

2. 创建虚拟网络网关

虚拟网络网关用于构建通往您本地设备的隧道。

主动/主动 (Active/Active) 配置

  1. 创建虚拟网络网关。
  2. 创建两个新的公共 IP 地址或使用现有的 IP。记下分配给虚拟网络网关的公共 IP 地址,因为这些将作为 Cloudflare WAN IPsec 隧道配置的客户方端点。
  3. 导航到之前创建的虚拟网络网关。
  4. 在 Configuration 中,启用 Active-active mode 并禁用 Gateway Private IPs。
  5. 选择 Create(创建)。

主动/备用 (Active/Standby) 配置

  1. 创建虚拟网络网关。
  2. 创建一个新的公共 IP 地址或使用现有的 IP。记下分配给虚拟网络网关的公共 IP 地址,因为这将作为 Cloudflare WAN IPsec 隧道配置的客户方端点。
  3. 选择您已创建的资源组和 VNET。
  4. 在 Configuration 中,禁用 Active-active mode 和 Gateway Private IPs。
  5. 选择 Create(创建)。

配置 Cloudflare WAN

  1. 在 Cloudflare 仪表板中创建 IPsec 隧道。
  2. 确保您具有以下设置:
    1. Interface address:Azure Local Network Gateway 只允许指定 /31 子网中的较低 IP 地址,因此请在 /31 子网内添加较高的 IP 地址。你将在后续步骤中于 Azure 配置对应的 /32 地址(参阅为 IPsec 隧道健康检查配置 Local Network Gateway)。有关详细信息,请参阅隧道端点。
    2. 客户方端点:与您的 Azure 虚拟网络网关相关联的公共 IP。例如,40.xxx.xxx.xxx。
    3. Cloudflare 端点:使用分配给您账户的 Cloudflare Anycast 地址之一,可在租用 IP ↗ 中获取。这也将是 Azure 中本地网络网关对应的 IP 地址。例如,162.xxx.xxx.xxx。
    4. 健康检查速率:保持选择默认选项 (Medium)。
    5. 健康检查类型:保持选择默认选项 (Reply)。
    6. 健康检查方向:保持选择默认选项 (Bidirectional)。
    7. 健康检查目标:选择 Custom(自定义)。
    8. 目标地址:输入与 Customer endpoint(客户端点) 字段中使用的相同地址。
    9. 稍后添加预共享密钥:选择此选项以创建一个稍后将在 Azure 中使用的 PSK。
    10. 重放保护:启用。
  3. 如果使用 Active/Active 配置,请选择 Add IPsec tunnel 并重复步骤 2,创建第二条 Cloudflare WAN IPsec 隧道。两条隧道使用相同的 Cloudflare endpoint。
  4. 完成后选择 Add Tunnels。
  5. Cloudflare 仪表板将为您显示隧道列表。编辑您创建的隧道 > 选择 Generate a new pre-shared key(生成新的预共享密钥) > 复制生成的密钥。如果使用的是主动/主动配置,请在第二个隧道上选择 Change to a new custom pre-shared key(更改为新的自定义预共享密钥),并使用为第一个隧道生成的 PSK。
  6. 为 Azure Virtual Network 子网创建静态路由,并将新建的隧道指定为下一跳。

完成 Azure 配置

1. 创建本地网络网关

本地网络网关(Local Network Gateway)通常指代您的本地物理位置。在本例中,本地网络网关代表连接的 Cloudflare 侧。

我们建议为您 Cloudflare 的 IPsec 隧道创建一个本地网络网关。

  1. 创建一个新的本地网络网关。
  2. 在 Instance details > Endpoint 中,选择 IP address,然后在 IP 地址字段中输入 Cloudflare anycast 地址。
  3. 在 Address space(s) 中,指定希望通过 Cloudflare WAN 连接远程访问的子网地址范围。例如,如果需要访问 IP 范围为 192.168.1.0/24、且已连接到 Cloudflare WAN 租户的网络,就将 192.168.1.0/24 添加到 Local Network Gateway 地址空间。
  4. 前往 Advanced 选项卡 > BGP settings,确保选择 No。

2. 为 IPsec 隧道健康检查配置本地网络网关

Cloudflare WAN 使用隧道健康检查监控隧道是否可用。

隧道健康检查利用了从 IPsec 隧道 Cloudflare 侧发送到远程端点 (Azure) 的 ICMP 探测包。探测包从隧道的接口地址发送,您需要在两个地方指定该地址:

  1. Cloudflare 仪表板:在您的 IPsec 隧道配置中,作为虚拟隧道接口 (VTI) 的地址(以便 Cloudflare 知道从哪个地址发送探测)。Cloudflare 要求此地址采用带有 /31 子网掩码的无类别域间路由 (CIDR) 表示法。
  2. Azure 门户:在您的 VPN 站点的地址空间中(以便 Azure 将探测响应路由回隧道)。Azure 要求此地址采用带有 /32 子网掩码的 CIDR 表示法。

Cloudflare 建议客户为每个 IPsec 隧道选择一个唯一的 /31 子网(RFC 1918 - 专用互联网的地址分配 ↗),该子网被视为点对点链路,并提供了满足这两个要求的理想寻址方案。

示例:

  • 选择 10.252.3.55/31 作为您的点对点链路子网。
  • 在 Cloudflare 仪表板中,将 10.252.3.55/31 设置为隧道的 IPv4 接口地址(参阅配置 Cloudflare WAN)。
  • 在 Azure 门户中,将 10.252.3.55/32 添加到 Local Network Gateway 的 Address space。

要配置本地网络网关 (Local Network Gateway) 的地址空间以支持隧道健康检查:

  1. 编辑在上一节中配置的本地网络网关。
  2. 选择 Connections(连接)。
  3. 在 Address Space(s) 下,使用 CIDR 表示法添加 Cloudflare 仪表板中 IPsec 隧道的 Interface Address(例如 10.252.3.55/32)。
  4. 如果使用 Active/Active 配置,还要在 Address Space(s) 下,以 CIDR 表示法添加 Cloudflare 仪表板中第二条 IPsec 隧道的 Interface Address(例如 10.252.3.56/32)。必须在 Local Network Gateway 地址空间中配置两条隧道的接口地址,才能确保两条隧道均保持健康。
  5. 选择 Save(保存)。

3. 创建 IPsec VPN 连接

创建您的 VPN 连接时,选择以下设置:

  1. Virtual network gateway(虚拟网络网关):选择您在创建虚拟网络网关中创建的虚拟网络网关。
  2. Local network gateway(本地网络网关):选择在创建本地网络网关中创建的本地网络网关。
  3. Use Azure Private IP Address(使用 Azure 私有 IP 地址):已禁用
  4. BGP:已禁用
  5. IPsec / IKE 策略:Custom(自定义)
    1. IKE 阶段 1
      1. Encryption(加密):GCMAES256
      2. Integrity/PRF(完整性/PRF):SHA384
      3. DH Group(DH 组):ECP384
    2. IKE 阶段 2 (IPsec)
      1. IPsec Encryption(IPsec 加密):GCMAES256
      2. IPsec Integrity(IPsec 完整性):GCMAES256
      3. PFS Group(PFS 组):ECP384
    3. 以 KB 为单位的 IPsec SA 生存周期:0
    4. 以秒为单位的 IPsec SA 生存周期:28800
    5. 使用基于策略的流量选择器:禁用
    6. 以秒为单位的 DPD 超时时间:45
    7. 连接模式:InitiatorOnly(仅限发起方)
    8. 使用自定义流量选择器:已禁用
  6. 创建连接后,选择 Settings(设置)> Authentication(身份验证),并 input 您的 PSK(这需要与 Cloudflare WAN 配置中使用的 PSK 相匹配)。

重复此过程,为连接到对应于冗余 Cloudflare Anycast IP 地址的本地网络网关定义设置。

4. 通过 Cloudflare WAN 和 Cloudflare Gateway 路由所有互联网流量

Cloudflare Zero Trust 客户可以通过 Cloudflare WAN 将流向互联网的流量路由到互联网,使其通过 Cloudflare Gateway。

Microsoft 不允许在本地网络网关的“地址空间”下指定默认路由 (0.0.0.0/0)。但是,可以通过使用路由汇总来绕过此限制。

  1. 前往 Local network gateways 并选择目标对象。
  2. 前往 Configuration > Address Space(s),并指定以下两个子网:0.0.0.0/1 和 128.0.0.0/1。
  3. 不要删除配置用于支持隧道健康检查的子网。
  4. 选择 Save(保存)。

安装 Cloudflare Zero Trust CA 证书

如果你选择通过 Cloudflare WAN 路由所有 Internet 流量,并希望使用 HTTPS TLS 解密,则必须在用户设备上安装并信任 Cloudflare Zero Trust 根证书颁发机构 (CA) 证书。你可以安装 Cloudflare 提供的证书(默认选项),也可以生成自己的自定义证书并将其上传到 Cloudflare。

有关如何安装根 CA 证书的更多详细信息,请参阅 Cloudflare Zero Trust 文档中的用户侧证书。

安装根 CA 证书后,打开 Web 浏览器或使用 curl 验证互联网连接:

curl https://ipinfo.io
{
	"ip": "104.xxx.xxx.225",
	"city": "Reston",
	"region": "Virginia",
	"country": "US",
	"loc": "xx.xxxx,-xx.xxxx",
	"org": "AS13335 Cloudflare, Inc.",
	"postal": "20190",
	"timezone": "America/New_York",
	"readme": "https://ipinfo.io/missingauth"
}

验证连接并禁用 Azure 虚拟网络网关的防重放保护

一旦您确定已建立连接,Cloudflare 建议您禁用 Azure 虚拟网络网关站点到站点 VPN 连接的防重放保护。这可以通过 Microsoft Azure API 来实现。

  1. 通过 PowerShell 确定 API 令牌:
Get-AzAccessToken
Token: eyJ0e<REDACTED>AH-PdSPg
ExpiresOn : 04/08/2024 23:32:47 +00:00
Type      : Bearer
TenantId  : xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
UserId    : [email protected]
  1. 发起 API 调用以显示与 Azure 虚拟网络网关相关联的站点到站点 VPN 连接的详细信息(GET 请求):
curl --location 'https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}?api-version=2022-05-01' \
--header 'Authorization: Bearer eyJ0e<REDACTED>AH-PdSPg'
  1. 将整个响应复制/粘贴到文本编辑器中:
{
    "name": "{{virtualNetworkGatewayName}}",
    "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}",
    "etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
    "type": "Microsoft.Network/virtualNetworkGateways",
    "location": "eastus"
    },
    "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "packetCaptureDiagnosticState": "None",
        "enablePrivateIpAddress": false,
        "isMigrateToCSES": false,
        "ipConfigurations": [
            {
                "name": "default",
                "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
                "etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
                "type": "Microsoft.Network/virtualNetworkGateways/ipConfigurations",
                "properties": {
                    "provisioningState": "Succeeded",
                    "privateIPAllocationMethod": "Dynamic",
                    "publicIPAddress": {
                        "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/publicIPAddresses/{{virtualNetworkGatewayPublicIpAddress}}"
                    },
                    "subnet": {
                        "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworks/{{virtualNetworkGatewayName}}/subnets/GatewaySubnet"
                    }
                }
            }
        ],
        "natRules": [],
        "virtualNetworkGatewayPolicyGroups": [],
        "enableBgpRouteTranslationForNat": false,
        "disableIPSecReplayProtection": false,
        "sku": {
            "name": "VpnGw2AZ",
            "tier": "VpnGw2AZ",
            "capacity": 2
        },
        "gatewayType": "Vpn",
        "vpnType": "RouteBased",
        "enableBgp": false,
        "activeActive": false,
        "bgpSettings": {
            "asn": 65515,
            "bgpPeeringAddress": "172.25.40.30",
            "peerWeight": 0,
            "bgpPeeringAddresses": [
                {
                    "ipconfigurationId": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
                    "defaultBgpIpAddresses": [
                        "172.25.40.30"
                    ],
                    "customBgpIpAddresses": [],
                    "tunnelIpAddresses": [
                        "{{CF ANYCAST IP}}"
                    ]
                }
            ]
        },
        "gatewayDefaultSite": {
            "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/localNetworkGateways/{{localNetworkGatewayName}}"
        },
        "vpnGatewayGeneration": "Generation2",
        "allowRemoteVnetTraffic": false,
        "allowVirtualWanTraffic": false
    }
}
  1. 找到控制禁用 IPsec 防重放保护的行,将其从 false 更改为 true:
"disableIPSecReplayProtection": true
  1. 在后续 API 调用(PUT 请求)中上传整个响应:
curl --location --request PUT \
'https://management.azure.com/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}?api-version=2022-05-01' \
--header "Authorization: Bearer eyJ0e<REDACTED>AH-PdSPg" \
--header "Content-Type: application/json" \
--data '{
    "name": "{{virtualNetworkGatewayName}}",
    "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}",
    "etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
    "type": "Microsoft.Network/virtualNetworkGateways",
    "location": "eastus"
    },
    "properties": {
        "provisioningState": "Succeeded",
        "resourceGuid": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "packetCaptureDiagnosticState": "None",
        "enablePrivateIpAddress": false,
        "isMigrateToCSES": false,
        "ipConfigurations": [
            {
                "name": "default",
                "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
                "etag": "W/\"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx\"",
                "type": "Microsoft.Network/virtualNetworkGateways/ipConfigurations",
                "properties": {
                    "provisioningState": "Succeeded",
                    "privateIPAllocationMethod": "Dynamic",
                    "publicIPAddress": {
                        "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/publicIPAddresses/{{virtualNetworkGatewayPublicIpAddress}}"
                    },
                    "subnet": {
                        "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworks/{{virtualNetworkGatewayName}}/subnets/GatewaySubnet"
                    }
                }
            }
        ],
        "natRules": [],
        "virtualNetworkGatewayPolicyGroups": [],
        "enableBgpRouteTranslationForNat": false,
        "disableIPSecReplayProtection": true,
        "sku": {
            "name": "VpnGw2AZ",
            "tier": "VpnGw2AZ",
            "capacity": 2
        },
        "gatewayType": "Vpn",
        "vpnType": "RouteBased",
        "enableBgp": false,
        "activeActive": false,
        "bgpSettings": {
            "asn": 65515,
            "bgpPeeringAddress": "172.25.40.30",
            "peerWeight": 0,
            "bgpPeeringAddresses": [
                {
                    "ipconfigurationId": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/virtualNetworkGateways/{{virtualNetworkGatewayName}}/ipConfigurations/default",
                    "defaultBgpIpAddresses": [
                        "172.25.40.30"
                    ],
                    "customBgpIpAddresses": [],
                    "tunnelIpAddresses": [
                        "{{CF ANYCAST IP}}"
                    ]
                }
            ]
        },
        "gatewayDefaultSite": {
            "id": "/subscriptions/{{subscriptionId}}/resourceGroups/{{resourceGroupName}}/providers/Microsoft.Network/localNetworkGateways/{{localNetworkGatewayName}}"
        },
        "vpnGatewayGeneration": "Generation2",
        "allowRemoteVnetTraffic": false,
        "allowVirtualWanTraffic": false
    }
}'
  1. 在 Cloudflare 仪表板中保持勾选重放保护设置,并等待几分钟后再重新验证连接。

这篇文档对您有帮助吗?