检查 VPN 状态

配置对等 VPN 网关后,请检查以下组件,确保它们与 Cloud VPN 正常通信:

  • 检查已配置的高可用性 VPN 隧道或传统 VPN 隧道的状态,包括操作状态。
  • 检查高可用性 VPN 网关上隧道的高可用性状态。
  • 查看 Cloud Router 边界网关协议 (BGP) 会话的状态或 Cloud Router 所通告的路由。

如需详细了解 Cloud VPN,请参阅以下资源:

  • 如需了解在设置 Cloud VPN 之前需要考虑的最佳实践,请参阅最佳实践

  • 如需详细了解 Cloud VPN,请参阅 Cloud VPN 概览

  • 如需了解本页面中所用术语的定义,请参阅关键术语

检查高可用性 VPN 隧道

此过程用于检查高可用性 VPN 网关的两个接口上的隧道状态。

控制台

  1. 在 Google Cloud 控制台中,转到 VPN 页面。

    转到 VPN

  2. 查看 VPN 隧道状态BGP 会话状态

  3. 如需查看隧道详情,请点击隧道的名称

  4. 日志下,点击查看以查看 Cloud Logging 日志。

  5. 您还可以修改与该隧道关联的 BGP 会话。

gcloud

要查看隧道状态,需要执行两个步骤。首先,确定隧道名称和区域,然后使用 describe 命令选项查看隧道详细信息。

在以下命令中,替换以下选项:

  • PROJECT_ID:您的项目的 ID
  • GW_NAME:网关的名称
  • REGION:网关或隧道所在的区域
  • NAME:隧道的名称

如需查看隧道状态,请完成以下步骤:

  1. 找到您要检查其状态的 VPN 隧道的名称和区域。您可使用以下任一方法来识别隧道:

    1. 选项 1:如需列出您项目中的所有 VPN 隧道,请运行以下命令:

      gcloud compute vpn-tunnels list
        --project=PROJECT_ID
      

      命令输出应类似于以下示例:

      NAME                REGION       GATEWAY      VPN_INTERFACE  PEER_ADDRESS
      tunnel-a-to-b-if-0  us-central1  ha-vpn-gw-a  0              10.242.123.165
      tunnel-a-to-b-if-1  us-central1  ha-vpn-gw-a  1              10.220.75.213
      tunnel-b-to-a-if-0  us-central1  ha-vpn-gw-b  0              10.242.127.148
      tunnel-b-to-a-if-1  us-central1  ha-vpn-gw-b  1              10.220.66.156
      
    2. 选项 2:如果您知道包含隧道的 VPN 网关的名称,要检索该网关的关联隧道的列表,请运行以下命令:

      gcloud compute vpn-gateways describe GW_NAME \
        --region=REGION \
        --project=PROJECT_ID \
        --format='flattened(tunnels)'
      
  2. 获知隧道的名称和区域后,使用 vpn-tunnels 命令的 describe 选项确定隧道的状态:

    gcloud compute vpn-tunnels describe NAME \
       --region=REGION \
       --project=PROJECT_ID \
       --format='flattened(status,detailedStatus)'
    

    此时将返回基本状态消息和更详细的消息。命令输出应类似于以下示例。如需完整列表,请省略 --format 选项。

    detailedStatus: Tunnel is up and running.
    

    下面四个命令输出示例显示了相互连接的每个高可用性 VPN 网关(共两个)上的隧道对的完整列表。也就是说,在 ha-vpn-gw-a 上,interface 0interface 1 上的隧道连接到 ha-vpn-gw-b 的相应接口上的隧道。

    示例 1:tunnel-a-to-b-if-0

     creationTimestamp: '2018-10-11T13:12:33.851-07:00'
     description: ''
     detailedStatus: Tunnel is up and running.
     id: '2919847494518181982'
     ikeVersion: 2
     kind: compute#vpnTunnel
     labelFingerprint: LABEL_FINGERPRINT
     localTrafficSelector:
     — 0.0.0.0/0
     name: tunnel-a-to-b-if-0
     peerIp: GW_A_IF_0_IP
     region: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1
     remoteTrafficSelector:
     — 0.0.0.0/0
     router: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/routers/router-a
     selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnTunnels/tunnel-a-to-b-if-0
     sharedSecret: '*************'
     sharedSecretHash: SECRET_HASH
     vpnGateway: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnGateways/ha-vpn-gw-a
     vpnGatewayInterface: 0
    

    示例 2:tunnel-a-to-b-if-1

     creationTimestamp: '2018-10-11T13:14:21.630-07:00'
     description: ''
     detailedStatus: Tunnel is up and running.
     id: '178016642781024754'
     ikeVersion: 2
     kind: compute#vpnTunnel
     labelFingerprint: LABEL_FINGERPRINT
     localTrafficSelector:
     —0.0.0.0/0
     name: tunnel-a-to-b-if-1
     peerIp: GW_B_IF_1_IP
     region: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1
     remoteTrafficSelector:
     — 0.0.0.0/0
     router: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/routers/router-a
     selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnTunnels/tunnel-a-to-b-if-1
     sharedSecret: '*************'
     sharedSecretHash: SECRET_HASH
     vpnGateway: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnGateways/ha-vpn-gw-a
     vpnGatewayInterface: 1
    

    示例 3:tunnel-b-to-a-if-0

     creationTimestamp: '2018-10-11T13:16:19.345-07:00'
     description: ''
     detailedStatus: Tunnel is up and running.
     id: '1183416925692236156'
     ikeVersion: 2
     kind: compute#vpnTunnel
     labelFingerprint: LABEL_FINGERPRINT
     localTrafficSelector:
     — 0.0.0.0/0
     name: tunnel-b-to-a-if-0
     peerIp: GW_A_IF_0_IP
     region: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1
     remoteTrafficSelector:
     — 0.0.0.0/0
     router: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/routers/router-b
     selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnTunnels/tunnel-b-to-a-if-0
     sharedSecret: '*************'
     sharedSecretHash: SECRET_HASH
     vpnGateway: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnGateways/ha-vpn-gw-b
     vpnGatewayInterface: 0
    

    示例 4:tunnel-b-to-a-if-1

     creationTimestamp: '2018-10-11T13:19:01.562-07:00'
     description: ''
     detailedStatus: Tunnel is up and running.
     id: '8199247227773914842'
     ikeVersion: 2
     kind: compute#vpnTunnel
     labelFingerprint: LABEL_FINGERPRINT
     localTrafficSelector:
     — 0.0.0.0/0
     name: tunnel-b-to-a-if-1
     peerIp: GW_A_IF_1_IP
     region: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1
     remoteTrafficSelector:
     — 0.0.0.0/0
     router: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/routers/router-b
     selfLink: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnTunnels/tunnel-b-to-a-if-1
     sharedSecret: '*************'
     sharedSecretHash: SECRET_HASH
     vpnGateway: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/us-central1/vpnGateways/ha-vpn-gw-b
     vpnGatewayInterface: 1
    

API

如需查看隧道详情,您可以使用以下任一 API 调用:

  • 要列出特定项目和区域中所有 VPN 隧道的特性和状态,请使用 vpnTunnels.list 方法发出 GET 请求:

    GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels
    
  • 如需列出特定项目和区域中特定隧道的特性和状态,请使用 vpnTunnels.get 方法发出 GET 请求:

    GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels/TUNNEL_NAME
    

检查传统 VPN 隧道

此过程可用于检查传统 VPN 网关上隧道的状态。

控制台

  1. 在 Google Cloud 控制台中,转到 VPN 页面。

    转到 VPN

  2. 查看 VPN 隧道状态BGP 会话状态

  3. 如需查看隧道详情,请点击隧道的名称

  4. 日志下,点击查看以查看 Logging 日志。

  5. 您还可以修改与该隧道关联的 BGP 会话。

gcloud

检查传统 VPN 隧道状态的过程与检查高可用性 VPN 的类似。

在以下命令中,替换以下选项:

  • PROJECT_ID:您的项目的 ID
  • GW_NAME:网关的名称
  • REGION:网关或隧道所在的区域
  • NAME:隧道的名称

如需查看隧道状态,请完成以下步骤:

  1. 找到您要检查其状态的 VPN 隧道的名称和区域。您可使用以下任一方法来识别隧道:

    1. 选项 1:如需列出您项目中的所有 VPN 隧道,请运行以下命令:

      gcloud compute vpn-tunnels list
        --project=PROJECT_ID
      
    2. 选项 2:如果您知道包含隧道的 VPN 网关的名称,要检索该网关的关联隧道的列表,请运行以下命令:

      gcloud compute target-vpn-gateways describe GW_NAME \
        --region=REGION \
        --project=PROJECT_ID \
        --format='flattened(tunnels)'
      
  2. 通过运行以下命令描述隧道以确定其状态。此时将返回基本状态消息和更详细的消息。如需完整列表,请省略 --format 选项。

    gcloud compute vpn-tunnels describe NAME \
        --region=REGION \
        --project=PROJECT_ID \
        --format='flattened(status,detailedStatus)'
    

API

如需查看隧道详情,您可以使用以下任一 API 调用:

  • 要列出特定项目和区域中所有 VPN 隧道的特性和状态,请使用 vpnTunnels.list 方法发出 GET 请求:

    GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels
    
  • 如需列出特定项目和区域中特定隧道的特性和状态,请使用 vpnTunnels.get 方法发出 GET 请求:

    GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels/TUNNEL_NAME
    

检查传统 VPN 转发规则

此过程用于检查您为传统 VPN 网关创建的转发规则。

控制台

  1. 在 Google Cloud 控制台中,转到 VPN 页面。

    转到 VPN

  2. 点击网关名称

  3. VPN 详细信息页面上,查看您创建的转发规则。

gcloud

如需查看特定区域中传统 VPN 网关的转发规则,请运行以下命令:

gcloud compute target-vpn-gateways describe GW_NAME
    --region=REGION \
    --project=PROJECT_ID

API

如需查看特定区域中传统 VPN 网关的转发规则,请使用 targetVpnGateways.get 方法。将 RESOURCE_ID 替换为网关的名称。

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/targetVpnGateways/RESOURCE_ID

解读隧道状态消息

如需从 Google Cloud Console 或 Google Cloud CLI 解读隧道状态消息,请使用下表。

状态 详细状态消息 备注
正在分配资源 正在分配资源。VPN 隧道即将启动。 新创建的 Cloud VPN 隧道的初始状态。
正在等待完整配置 正在等待路由配置。 正在准备路由或路由配置。
首次握手 对等互连握手断开,原因未知。即将重试。 与对等 VPN 的第 1 阶段 (IKE SA) 协商正在进行中。此协商可能已失败了至少一次。
已建立 隧道已启动并正在运行。 隧道已启动,并且已配置了路由。
无传入数据包 没有来自对等体的传入数据包 未从对等 VPN 网关接收到流量。

检查高可用性 VPN 网关的高可用性状态

如需检查高可用性 VPN 网关上隧道的高可用性配置状态,请使用 Google Cloud 控制台、compute vpn-gateways get-status 命令或 vpnGateways.getStatus 方法。

输出显示了与高可用性 VPN 网关相连的每个对等网关关联的 VPN 隧道的高可用性冗余要求状态。

对等网关可以是另一个高可用性 VPN 网关,也可以是外部 VPN 网关。如果高可用性 VPN 网关连接了多个对等网关,则会显示多个高可用性配置状态,每个状态对应一个对等网关。

命令输出通过以下方式显示了正确的隧道数量和覆盖范围:

  • 配置了足够冗余(覆盖范围)的 VPN 网关会显示以下状态:
    HighAvailabilityRedundancyRequirementState: CONNECTION_REDUNDANCY_MET
  • 未配置足够冗余的 VPN 网关会显示以下状态:
    HighAvailabilityRedundancyRequirementState: CONNECTION_REDUNDANCY_NOT_MET
  • 如果您的高可用性 VPN 网关与其他高可用性 VPN 网关或对等网关之间未配置足够的隧道,则命令输出会显示以下状态:
    redundancyUnsatisfiedReason: INCOMPLETE_TUNNELS_COVERAGE

如需了解其他信息,请参阅查看日志和指标

控制台

  1. 在 Google Cloud 控制台中,转到 VPN 页面。

    转到 VPN

  2. 如需查看网关及其隧道的详情,请点击网关名称。对于高可用性 VPN 网关,您还可以查看其高可用性状态。

gcloud

如需显示高可用性 VPN 网关的隧道状态,请运行以下命令。替换以下内容:

  • GW_NAME:高可用性 VPN 网关的名称
  • REGION:网关所在的区域
gcloud compute vpn-gateways get-status GW_NAME \
    --region=REGION

以下命令输出示例显示了连接到具有两个接口的对等网关的高可用性 VPN 网关的信息:

  peerGateways:
  — peerExternalGateway: peer-gw
  tunnels:
  — localGatewayInterface: 0
    peerGatewayInterface: 0
    tunnelUrl:
    https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
    regions/us-central1/vpnTunnels/tunnel-a-to-on-prem-if-0
  — localGatewayInterface: 1
    peerGatewayInterface:1
    tunnelUrl:
    https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
    regions/us-central1/vpnTunnels/tunnel-a-to-on-prem-if-1
    HighAvailabilityRedundancyRequirementState:
      state: CONNECTION_REDUNDANCY_MET

以下命令输出示例针对的是相互连接的两个高可用性 VPN 网关。对于此类配置,请为每个高可用性 VPN 网关名称运行该命令:

  • 获取 ha-vpn-gw-a 的状态会显示它与 ha-vpn-gw-b 的连接:

    peerGateways:
    — peerGcpGateway: ha-vpn-gw-b
    tunnels:
    — localGatewayInterface: 0
      peerGatewayInterface: 0
      tunnelUrl:
      https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
      regions/us-central1/vpnTunnels/tunnel-a-to-b-if-0
    — localGatewayInterface: 1
      peerGatewayInterface: 1
      tunnelUrl:
      https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
      regions/us-central1/vpnTunnels/tunnel-a-to-b-if-1
      HighAvailabilityRedundancyRequirementState:
        state: CONNECTION_REDUNDANCY_MET
    
  • 获取 ha-vpn-gw-b 的状态会显示它与 ha-vpn-gw-a 的连接:

    peerGateways:
    — peerGcpGateway: ha-vpn-gw-a
    tunnels:
    — localGatewayInterface: 0
      peerGatewayInterface: 0
      tunnelUrl:
      https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
      regions/us-central1/vpnTunnels/tunnel-b-to-a-if-0
    — localGatewayInterface: 1
      peerGatewayInterface: 1
      tunnelUrl:
      https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
      regions/us-central1/vpnTunnels/tunnel-b-to-a-if-1
      HighAvailabilityRedundancyRequirementState:
        state: CONNECTION_REDUNDANCY_MET
    

以下命令输出示例针对的是一个连接到具有 2 个接口和 4 个 IP 地址的 AWS 虚拟网关的高可用性 VPN 网关:

  peerGateways:
  - peerExternalGateway: peer-gw
  tunnels:
   - localGatewayInterface: 0
     peerGatewayInterface: 0
     tunnelUrl:
     https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
     regions/us-central1/vpnTunnels/tunnel-a-to-aws-connection-0-ip0
   - localGatewayInterface: 0
     peerGatewayInterface: 1
     tunnelUrl:
     https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
     regions/us-central1/vpnTunnels/tunnel-a-to-aws-connection-0-ip1
   - localGatewayInterface: 1
     peerGatewayInterface: 2
     tunnelUrl:
     https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
     regions/us-central1/vpnTunnels/tunnel-a-to-aws-connection-1-ip0
   - localGatewayInterface: 1
     peerGatewayInterface: 3
     tunnelUrl:
     https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
     regions/us-central1/vpnTunnels/tunnel-a-to-aws-connection-1-ip1
     HighAvailabilityRedundancyRequirementState:
       state: CONNECTION_REDUNDANCY_MET

以下命令输出示例针对的是通过一个隧道相互连接的两个高可用性 VPN 网关。此配置不满足 99.99% 的可用性 SLA 要求:

  peerGateways:
    - peerGcpGateway: ha-vpn-gw-a
    tunnels:
    - localGatewayInterface: 0
      peerGatewayInterface: 0
      tunnelUrl:
      https://www.googleapis.com/compute/v1/projects/PROJECT_ID/
      regions/us-central1/vpnTunnels/tunnel-b-to-a-if-0
      HighAvailabilityRedundancyRequirementState:
        state: CONNECTION_REDUNDANCY_NOT_MET
      detailedStatus:
        redundancyUnsatisfiedReason: INCOMPLETE_TUNNELS_COVERAGE

API

如需获取特定项目和区域中特定高可用性 VPN 网关的状态,请使用 vpnGateways.getStatus 方法发出 GET 请求:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnGateways/GATEWAY_NAME/getStatus

检查 BGP 状态

对于将动态路由与 BGP 结合使用的隧道,您可检查 Cloud Router 路由器状态,查看路由器 BGP 会话的状态或 Cloud Router 路由器所通告的路由等详细信息。

后续步骤

  • 如需使用高可用性和高吞吐量场景或多个子网方案,请参阅高级配置
  • 如需帮助解决使用 Cloud VPN 时可能会遇到的常见问题,请参阅问题排查