为 P2S VPN 客户端播发自定义路由

你可能想要向所有点到站点 VPN 客户端播发自定义路由。 例如,当你在 VNet 中启用了存储终结点并希望远程用户能够通过 VPN 连接访问这些存储帐户时。 可以向所有远程用户播发存储终结点的 IP 地址,从而使到存储帐户的流量通过 VPN 隧道,而不是公共 Internet。 还可以使用自定义路由为 VPN 客户端配置强制隧道

Diagram of advertising custom routes.

Azure 门户

可以使用点到站点配置页上的 Azure 门户来播发自定义路由。 还可以根据需要,使用这些步骤来查看和修改/删除自定义路由。 如果要配置强制隧道,请参阅本文中的强制隧道部分。

Screenshot showing additional routes in the portal.

  1. 转到虚拟网络网关。
  2. 在左窗格中选择“点到站点配置”。
  3. 在“点到站点配置”页上,添加这些路由。 请勿使用空格。
  4. 在页面顶部选择“保存”。

PowerShell

若要播发自定义路由,请使用 Set-AzVirtualNetworkGateway cmdlet。 以下示例演示如何播发 Contoso 存储帐户表的 IP。

  1. Ping contoso.table.core.chinacloudapi.cn 并记录 IP 地址。 例如:

    C:\>ping contoso.table.core.chinacloudapi.cn
    Pinging table.by4prdstr05a.store.core.chinacloudapi.cn [13.88.144.250] with 32 bytes of data:
    
  2. 运行以下 PowerShell 命令:

    $gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>
    Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute 13.88.144.250/32
    
  3. 若要添加多个自定义路由,请使用逗号和空格分隔地址。 例如:

    Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute x.x.x.x/xx , y.y.y.y/yy
    

查看自定义路由

使用以下示例查看自定义路由:

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>
$gw.CustomRoutes | Format-List

删除自定义路由

使用以下示例删除自定义路由:

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute @0

强制隧道

可以通过将 0.0.0.0/1 和 128.0.0.0/1 作为自定义路由播发到客户端,将所有流量定向到 VPN 隧道。 将 0.0.0.0/0 分成两个较小子网的原因是,这些较小前缀比可能已在本地网络适配器上配置的默认路由更具体,因此,将在路由流量时首选这些前缀。

注意

不通过 VPN 网关提供 Internet 连接。 因此,会删除所有绑定到 Internet 的流量。

若要启用强制隧道,请使用以下命令:

$gw = Get-AzVirtualNetworkGateway -Name <name of gateway> -ResourceGroupName <name of resource group>
Set-AzVirtualNetworkGateway -VirtualNetworkGateway $gw -CustomRoute 0.0.0.0/1 , 128.0.0.0/1

后续步骤

有关 P2S 路由的详细信息,请参阅关于点到站点路由