列出 BGP 路徑

本頁面說明如何在個別邊界閘道協定 (BGP) 工作階段中列出已通告路徑和已學習路徑,協助您排除 Cloud Router 路徑問題。您可以在套用 BGP 路由政策到路由之前或之後,列出路由。如要排解已宣告和已學習的路線問題,建議您依序完成下列各節。

事前準備

gcloud

如要使用本指南中的指令列範例,請完成下列事項:

  1. 安裝或更新至最新版 Google Cloud CLI
  2. 設定預設地區和區域

API

如要使用本指南提供的 API 範例,請設定 API 存取權

在套用政策前列出 BGP 路由

主控台

請執行下列步驟:

  1. 前往 Trusted Cloud 控制台的「Cloud Router」頁面。

    前往 Cloud Router

  2. 在「Cloud Router」頁面中,按一下「BGP 工作階段」分頁標籤。

  3. 選取要列出的 BGP 工作階段同級節點。系統會顯示 BGP 工作階段詳細資料頁面。公告路徑會列在「公告路徑」部分。

gcloud

使用 gcloud compute routers list-bgp-routes 指令

gcloud compute routers list-bgp-routes ROUTER_NAME \
    --address-family=ADDRESS_FAMILY \
    --no-policy-applied \
    --peer=PEER_NAME \
    --region=REGION \
    --route-direction=ROUTE_DIRECTION

更改下列內容:

  • ROUTER_NAME:Cloud Router 的名稱

  • ADDRESS_FAMILY:要顯示路由的 IP 位址群組:

    • IPV4:適用於以 IPv4 為基礎的 BGP 位址
    • IPV6:適用於以 IPv6 為基礎的 BGP 位址
  • PEER_NAME:BGP 對等點的名稱

  • REGION:Cloud Router 所在的區域

  • ROUTE_DIRECTION:顯示路線的方向:

    • INBOUND:從 BGP 對等點學習的路徑
    • OUTBOUND:通告給 BGP 對等點的路徑

輸出結果會與下列內容相似:

---
asPaths:
- asns:
  - 64515
  type: AS_PATH_TYPE_SEQUENCE
destination:
  prefix: 192.168.1.0/24
med: 100
origin: BGP_ORIGIN_INCOMPLETE
---
asPaths:
- asns:
  - 64515
  type: AS_PATH_TYPE_SEQUENCE
destination:
  prefix: 192.168.2.0/24
med: 333
origin: BGP_ORIGIN_INCOMPLETE

API

請使用 routers.listBgpRoutes 方法

GET https://compute.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME/listBgpRoutes
{
  "addressFamily": "ADDRESS_FAMILY",
  "peer": "PEER_NAME",
  "policyApplied": FALSE,
  "routeType": "ROUTE_TYPE"
}

更改下列內容:

  • PROJECT_ID:包含 Cloud Router 的專案

  • REGION:Cloud Router 所在的區域

  • ROUTER_NAME:Cloud Router 的名稱

  • ADDRESS_FAMILY:要顯示路由的 IP 位址群組:

    • IPV4:適用於以 IPv4 為基礎的 BGP 位址
    • IPV6:適用於以 IPv6 為基礎的 BGP 位址
  • PEER_NAME:BGP 對等點的名稱

  • ROUTE_TYPE:要顯示的路線類型:

    • LEARNED:從 BGP 對等點學習的路徑
    • ADVERTISED:向 BGP 對等點宣傳的路由

輸出結果會與下列內容相似:

{
  "kind": "compute#routersListBgpRoutes",
  "result": [
    {
      "destination": {
        "prefix": "10.0.1.0/24"
      },
      "med": 100
    },
    {
      "destination": {
        "prefix": "10.0.2.0/24"
      },
      "med": 338
    }
  ]
}

列出套用政策後的 BGP 路由

主控台

  1. 前往 Trusted Cloud 控制台的「Cloud Router」頁面。

    前往 Cloud Router

  2. 在「Cloud Router」頁面中,按一下「BGP 工作階段」分頁標籤。

  3. 選取要列出的 BGP 工作階段同級節點。系統會顯示 BGP 工作階段詳細資料頁面。公告路徑會列在「公告路徑」部分。

gcloud

使用 gcloud compute routers list-bgp-routes 指令

gcloud compute routers list-bgp-routes ROUTER_NAME \
    --address-family=ADDRESS_FAMILY \
    --policy-applied \
    --peer=PEER_NAME \
    --region=REGION \
    --route-direction=ROUTE_DIRECTION

更改下列內容:

  • ADDRESS_FAMILY:要顯示路由的 IP 位址群組:

    • IPV4:適用於以 IPv4 為基礎的 BGP 位址
    • IPV6:適用於以 IPv6 為基礎的 BGP 位址
  • PEER_NAME:BGP 對等點的名稱

  • ROUTE_DIRECTION:顯示路線的方向:

    • INBOUND:從 BGP 對等點學習的路徑
    • OUTBOUND:通告給 BGP 對等點的路徑

輸出結果會與下列內容相似:

---
asPaths:
- asns:
- 64515
type: AS_PATH_TYPE_SEQUENCE
communities:
- 65535:65281
destination:
prefix: 192.168.1.0/24
med: 100
origin: BGP_ORIGIN_INCOMPLETE
---
asPaths:
- asns:
- 64515
type: AS_PATH_TYPE_SEQUENCE
communities:
- 65535:65281
destination:
prefix: 192.168.2.0/24
med: 333
origin: BGP_ORIGIN_INCOMPLETE

API

請使用 routers.listBgpRoutes 方法

GET https://compute.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME/listBgpRoutes
{
"addressFamily": "ADDRESS_FAMILY",
"peer": "PEER_NAME",
"policyApplied": TRUE,
"routeType": "ROUTE_TYPE"
}

更改下列內容:

  • PROJECT_ID:包含 Cloud Router 的專案

  • REGION:Cloud Router 所在的區域

  • ROUTER_NAME:Cloud Router 的名稱

  • ADDRESS_FAMILY:要顯示路由的 IP 位址群組:

    • IPV4:適用於以 IPv4 為基礎的 BGP 位址
    • IPV6:適用於以 IPv6 為基礎的 BGP 位址
  • PEER_NAME:BGP 對等點的名稱

  • ROUTE_TYPE:要顯示的路線類型:

    • LEARNED:從 BGP 對等點學習的路徑
    • ADVERTISED:向 BGP 對等點宣傳的路由

輸出結果會與下列內容相似:

{
  "kind": "compute#routersListBgpRoutes",
  "result": [
    {
      "destination": {
        "prefix": "10.0.1.0/24"
      },
      "asPaths": [
        {
          "type": "AS_PATH_TYPE_SEQUENCE",
          "asns": [
            64514
          ]
        }
      ],
      "origin": "BGP_ORIGIN_INCOMPLETE",
      "med": 100
    },
    {
      "destination": {
        "prefix": "10.0.2.0/24"
      },
      "asPaths": [
        {
          "type": "AS_PATH_TYPE_SEQUENCE",
          "asns": [
            64514
          ]
        }
      ],
      "origin": "BGP_ORIGIN_INCOMPLETE",
      "med": 338
    }
  ]
}

查看最佳動態路線

查看每個 VPC 的每個 Cloud Router 和每個區域最佳動態路徑:

gcloud

使用 gcloud compute routers get-status 指令

gcloud compute routers get-status ROUTER_NAME \
    --region=REGION

輸出內容包含下列資訊:

  • bestRoutesForRouter:代表特定 Cloud Router 的最佳路徑
  • bestRoutes:代表該 VPC 中 Cloud Router 每個地區的最佳路徑。

bestRoutesForRouter 的輸出結果會類似以下內容:

  bestRoutesForRouter:
  - asPaths:
    - asLists:
      - 65002
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2024-09-26T18:28:54.346-07:00'
    destRange: 192.168.1.0/24
    kind: compute#route
    network: https://www.googleapis.com/compute/projects/PROJECT_ID/global/networks/NETWORK_NAME
    nextHopIp: 169.254.0.2
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/vpnTunnels/vpc-demo-tunnel0
    priority: 100
    routeStatus: ACTIVE
    routeType: BGP
  - asPaths:
    - asLists:
      - 65002
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2024-09-27T12:44:56.575-07:00'
    destRange: 192.168.1.0/24
    kind: compute#route
    network: https://www.googleapis.com/compute/projects/PROJECT_ID/global/networks/NETWORK_NAME
    nextHopIp: 169.254.1.2
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/vpnTunnels/vpc-demo-tunnel1
    priority: 100
    routeStatus: ACTIVE
    routeType: BGP

bestRoutes 的輸出結果會類似以下內容:

  bestRoutes:
  - asPaths:
    - asLists:
      - 65002
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2024-09-26T18:33:50.505-07:00'
    destRange: 192.168.1.0/24
    kind: compute#route
    network: https://www.googleapis.com/compute/projects/PROJECT_ID/global/networks/NETWORK_NAME
    nextHopIp: 169.254.0.2
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/vpnTunnels/vpc-demo-tunnel0
    priority: 100
    routeType: BGP
  - asPaths:
    - asLists:
      - 65002
      pathSegmentType: AS_SEQUENCE
    creationTimestamp: '2024-09-27T12:46:49.028-07:00'
    destRange: 192.168.1.0/24
    kind: compute#route
    network: https://www.googleapis.com/compute/projects/PROJECT_ID/global/networks/NETWORK_NAME
    nextHopIp: 169.254.1.2
    nextHopOrigin: INCOMPLETE
    nextHopVpnTunnel: https://www.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/vpnTunnels/vpc-demo-tunnel1
    priority: 100
    routeType: BGP

輸出內容包含下列值:

  • PROJECT_ID:包含 Cloud Router 的專案

  • NETWORK_NAME:虛擬私有雲網路名稱

  • REGION:區域名稱

API

請使用 routers.getRouterStatus 方法

GET https://compute.googleapis.com/compute/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME/getRouterStatus

更改下列內容:

  • PROJECT_ID:包含 Cloud Router 的專案

  • REGION:Cloud Router 所在的區域

  • ROUTER_NAME:Cloud Router 的名稱

輸出內容包含下列資訊:

  • bestRoutes:代表該 VPC 中 Cloud Router 每個地區的最佳路徑。
  • bestRoutesForRouter:代表特定 Cloud Router 的最佳路徑

bestRoutes 的輸出結果會類似以下內容:

    "bestRoutes": [
      {
        "kind": "compute#route",
        "creationTimestamp": "2025-03-05T11:20:40.323-08:00",
        "network": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/NETWORK_NAME",
        "destRange": "200.0.0.0/24",
        "priority": 100,
        "nextHopIp": "169.254.0.1",
        "nextHopVpnTunnel": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels/TUNNEL_NAME",
        "routeType": "BGP",
        "asPaths": [
          {
            "pathSegmentType": "AS_SEQUENCE",
            "asLists": [
              65001
            ]
          }
        ],
        "nextHopOrigin": "INCOMPLETE"
      },

bestRoutesForRouter 的輸出結果會類似以下內容:

    "bestRoutesForRouter": [
      {
        "kind": "compute#route",
        "creationTimestamp": "2025-03-05T11:20:50.240-08:00",
        "network": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/NETWORK_NAME",
        "destRange": "10.2.1.0/24",
        "priority": 100,
        "nextHopIp": "169.254.0.1",
        "nextHopVpnTunnel": "https://www.googleapis.com/compute/v1/projects/PROJECT_NAME/regions/REGION/vpnTunnels/TUNNEL_NAME",
        "routeType": "BGP",
        "asPaths": [
          {
            "pathSegmentType": "AS_SEQUENCE",
            "asLists": [
              65001
            ]
          }
        ],
        "routeStatus": "ACTIVE",
        "nextHopOrigin": "INCOMPLETE"
      },
      {
        "kind": "compute#route",
        "creationTimestamp": "2025-03-05T01:50:01.725-08:00",
        "network": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/on-prem",
        "destRange": "200.0.0.0/24",
        "priority": 100,
        "nextHopIp": "169.254.0.1",
        "nextHopVpnTunnel": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels/TUNNEL_NAME",
        "routeType": "BGP",
        "asPaths": [
          {
            "pathSegmentType": "AS_SEQUENCE",
            "asLists": [
              65001
            ]
          }
        ],
        "routeStatus": "ACTIVE",
        "nextHopOrigin": "INCOMPLETE"
      },
      {
        "kind": "compute#route",
        "creationTimestamp": "2025-03-06T05:30:06.277-08:00",
        "network": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks/on-prem",
        "destRange": "10.2.1.0/24",
        "priority": 100,
        "nextHopIp": "169.254.1.1",
        "nextHopVpnTunnel": "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/vpnTunnels/TUNNEL_NAME",
        "routeType": "BGP",
        "asPaths": [
          {
            "pathSegmentType": "AS_SEQUENCE",
            "asLists": [
              65001
            ]
          }
        ],
        "routeStatus": "ACTIVE",
        "nextHopOrigin": "INCOMPLETE"
      }
    ],

輸出內容包含下列值:

  • PROJECT_ID:包含 Cloud Router 的專案

  • REGION:Cloud Router 所在的區域

  • ROUTER_NAME:Cloud Router 的名稱

  • TUNNEL_NAME:如果適用,VPN 通道的名稱

查看 VPC 轉送層路徑表

請執行下列步驟:

  1. 前往 Trusted Cloud 控制台的「Routes」頁面。

    前往「Routes」(路徑)

  2. 在「有效路徑」分頁中,選取要列出路徑的網路。

  3. 在「區域」清單中選取要列出路徑的區域,然後按一下「查看」