列出 BGP 路由

本頁面說明如何列出個別邊界閘道通訊協定 (BGP) 工作階段的通告路徑和取得路徑,這有助於排解 Cloud Router 路徑問題。您可以在路由套用 BGP 路由政策前後列出路由。如要排解已放送及已學習路徑的問題,建議依序完成下列各節的步驟。

事前準備

gcloud

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

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

API

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

列出套用政策前的 BGP 路由

控制台

請執行下列步驟:

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

    前往 Cloud Router

  2. 在「Cloud Router」頁面中,按一下「BGP sessions」分頁標籤。

  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. 前往 Cloud de Confiance 控制台的「Cloud Router」頁面。

    前往 Cloud Router

  2. 在「Cloud Router」頁面中,按一下「BGP sessions」分頁標籤。

  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
    }
  ]
}

查看最佳動態路線

依據每個 Cloud Router、每個區域和每個 VPC,查看最佳動態路徑:

gcloud

使用 gcloud compute routers get-status 指令

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

輸出內容包含下列資訊:

  • bestRoutesForRouter:代表特定 Cloud Router 的最佳路徑
  • bestRoutes:代表該虛擬私有雲的 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:代表該虛擬私有雲的 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. 前往 Cloud de Confiance 控制台的「Routes」(路徑) 頁面。

    前往「Routes」(路徑)

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

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