列出 BGP 路由

本頁面說明如何列出個別邊界閘道通訊協定 (BGP) 工作階段的 advertise 路由和 learned 路由,協助您排解 Cloud Router 路由問題。無論是否已對路由套用 BGP 路由政策,您都可以列出路由。如要排解 advertised 和 learned 路由的問題,建議您依序完成下列各節。

事前準備

gcloud

如要使用本指南中的指令列範例,請按照下列步驟操作:

  1. 安裝或更新至最新版本的 Google Cloud CLI。
  2. 設定預設區域和可用區。

API

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

列出套用政策前的 BGP 路由

控制台

請執行下列步驟:

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

    前往 Cloud Router

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

  3. 選取要列出的 BGP 工作階段對等互連。系統隨即會顯示 BGP 工作階段詳細資料頁面。「Advertised routes」(通告路徑) 部分會列出通告路徑。

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 對等互連 advertise 的路由

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

---
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 對等互連 advertise 的路由

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

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

列出套用政策後的 BGP 路由

控制台

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

    前往 Cloud Router

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

  3. 選取要列出的 BGP 工作階段對等互連。系統隨即會顯示 BGP 工作階段詳細資料頁面。「Advertised routes」(通告路徑) 部分會列出通告路徑。

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 對等互連 advertise 的路由

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

---
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 對等互連 advertise 的路由

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

{
  "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、每個區域和每個虛擬私有雲的最佳動態路徑:

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 通道名稱 (如適用)

查看虛擬私有雲轉送層路由表

請執行下列步驟:

  1. 前往 Google Cloud 控制台的「Routes」(路徑) 頁面。

    前往「Routes」(路徑)

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

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