對等互連兩個虛擬私有雲網路

瞭解如何使用 Google Cloud 控制台對等互連兩個虛擬私有雲 (VPC) 網路。

假設有一個機構 organization-a 需要在 project-a 中的 network-aproject-b 中的 network-b 之間建立虛擬私有雲網路對等互連。如要成功建立虛擬私有雲網路對等互連,network-anetwork-b 的管理員必須個別設定對等互連關聯。

完成本文中的步驟後,您將建立下列設定:

對等互連已啟用。
兩個有啟用對等連線的網路 (按一下可放大)。

事前準備

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Compute Engine API.

    Enable the API

  5. Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「身分與存取權管理」頁面
    2. 選取專案。
    3. 按一下 「授予存取權」
    4. 在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。

    5. 在「請選擇角色」清單中,選取角色。
    6. 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
    7. 按一下 [Save]
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  7. Make sure that billing is enabled for your Google Cloud project.

  8. Enable the Compute Engine API.

    Enable the API

  9. Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor

    Check for the roles

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to the IAM page.

      前往「身分與存取權管理」頁面
    2. 選取專案。
    3. 按一下 「授予存取權」
    4. 在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。

    5. 在「請選擇角色」清單中,選取角色。
    6. 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
    7. 按一下 [Save]
  10. 針對第二個專案重複執行這些步驟。本快速入門說明如何對等互連位於不同專案中的虛擬私有雲網路。

建立兩個虛擬私有雲網路

在本節中,您會建立兩個 VPC 網路,每個網路都位於不同的專案中。

在第一個專案中建立 network-asubnet-a

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。

    前往「VPC networks」(虛擬私有雲網路)

  2. 按一下「建立虛擬私有雲網路」

  3. 在「Name」(名稱) 欄位中輸入 network-a

  4. 在「New subnet」(新的子網路) 區段中,指定下列項目:

    1. 在「Name」(名稱) 欄位中輸入 subnet-a
    2. 選取任一區域
    3. 在「IPv4 範圍」欄位中輸入 10.0.1.0/24
    4. 按一下 [完成]
  5. 在「IPv4 防火牆規則」分頁中,點選包含名為 NETWORK-allow-custom 的預先定義輸入防火牆規則的列右側的「編輯」

    1. 取消選取「使用子網路的 IPv4 範圍」
    2. 在「Other IPv4 ranges」(其他 IPv4 範圍) 中輸入 10.0.0.0/20。輸入這個範圍可確保對等網路中的資源可以彼此通訊,並讓您日後新增更多子網路,而無須更新防火牆規則。
    3. 按一下「確認」。
  6. 按一下 [建立]。

在第二個專案中建立 network-bsubnet-b

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。

    前往「VPC networks」(虛擬私有雲網路)

  2. 按一下「建立虛擬私有雲網路」

  3. 在「Name」(名稱) 欄位中輸入 network-b

  4. 在「New subnet」(新的子網路) 區段中,指定下列項目:

    1. 在「Name」(名稱) 欄位中輸入 subnet-b
    2. 選取任一區域
    3. 在「IPv4 範圍」欄位中輸入 10.0.8.0/24
    4. 按一下 [完成]
  5. 在「IPv4 防火牆規則」分頁中,點選包含名為 NETWORK-allow-custom 的預先定義輸入防火牆規則的列右側的「編輯」

    1. 取消選取「使用子網路的 IPv4 範圍」
    2. 在「Other IPv4 ranges」(其他 IPv4 範圍) 中輸入 10.0.0.0/20。輸入這個範圍可確保對等網路中的資源可以彼此通訊,並讓您日後新增更多子網路,而無須更新防火牆規則。
    3. 按一下「確認」。
  6. 按一下 [建立]。

同類應用程式 network-anetwork-b

在本節中,您將設定 network-anetwork-b 建立對等連線。

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。

    前往「VPC Network Peering」(虛擬私有雲網路對等互連)

  2. 點選「建立連線」

  3. 按一下「繼續」

  4. 針對連線的這一端輸入 peer-ab 做為「Name」(名稱)。

  5. 在「您的 VPC 網路」下方,選取 network-a

  6. 將「對等互連虛擬私有雲網路」圓形按鈕設為 In another project

  7. 指定其他專案的「Project ID」(專案 ID)

  8. 指定另一個網路 (network-b) 的「VPC 網路名稱」

  9. 選取「Import custom routes」(匯入自訂路徑) 和「Export custom routes」(匯出自訂路徑)

  10. 按一下 [建立]。

此時,對等互連狀態仍然是 INACTIVE,因為在 project-bnetwork-b 中沒有相符的設定。

當對等互連狀態變成 ACTIVE 時,VPC 網路對等互連會自動交換子網路路徑。 Google Cloud 也會透過對等互連連線匯入或匯出自訂路徑 (靜態路徑和動態路徑),以交換這些路徑。網路的兩端都必須設定為交換自訂路徑,才能共用這些路徑。詳情請參閱「匯入並匯出自訂路徑」。

若要查看目前的對等互連狀態,請查看對等互連連線:

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。

    前往「VPC Network Peering」(虛擬私有雲網路對等互連)

  2. 選取 peer-ab。在「對等互連連線詳細資料」頁面上,狀態顯示為 Inactive. Waiting for the connection to be created by network-b

同類應用程式 network-bnetwork-a

在本節中,您會建立從 network-bnetwork-a 的對等互連設定,讓兩端的互連變成 ACTIVE

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。

    前往「VPC Network Peering」(虛擬私有雲網路對等互連)

  2. 點選「建立連線」

  3. 按一下「繼續」

  4. 針對連線的這一端輸入 peer-ba 做為「Name」(名稱)。

  5. 在「Your VPC network」(您的 VPC 網路) 底下,選取 network-b

  6. 將「對等互連虛擬私有雲網路」圓形按鈕設為 In another project

  7. 指定其他專案的「Project ID」(專案 ID)

  8. 指定另一個網路 (network-b) 的「VPC 網路名稱」

  9. 選取「Import custom routes」(匯入自訂路徑) 和「Export custom routes」(匯出自訂路徑)

  10. 按一下 [建立]。

VPC 網路對等互連變成 ACTIVE

一旦對等互連變成 ACTIVE 狀態,子網路路徑和自訂路徑便會交換,允許流量在網路資源之間流動。

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。

    前往「VPC Network Peering」(虛擬私有雲網路對等互連)

  2. 在「VPC 網路對等互連」頁面中,您建立的連線狀態會顯示 ACTIVE

  3. 前往另一個專案中的「VPC Network Peering」(VPC 網路對等互連) 頁面,確認狀態是否也顯示 ACTIVE

您現在可在 VPC 網路節點看到對等網路 CIDR 前置字串的路徑。這些路徑是為啟用的對等互連連線而產生的隱含路徑,並且沒有對應的路徑資源。下列程序會列出 project-a 所有虛擬私有雲網路的路徑。

主控台

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

    前往「Routes」(路徑)

  2. 在「Network」(網路) 和「Region」(區域) 中,選取 network-a 和您建立 subnet-a 的區域,然後按一下「View」(查看)

  3. 在路徑清單中,subnet-bPeering subnet 路徑。

清除所用資源

如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。

刪除專案

如要刪除您建立的專案,請按照下列步驟操作:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

刪除個別資源

如果您不想刪除整個專案,請刪除 VPC 網路對等互連連線和您建立的 VPC 網路。

您必須先刪除網路的 VPC 網路對等互連連線,才能刪除網路。

刪除 VPC 網路對等互連連線

如要刪除 VPC 網路對等互連連線,請按照下列步驟操作:

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。

    前往「VPC Network Peering」(虛擬私有雲網路對等互連)

  2. 找出您要移除的對等互連,並選取旁邊的核取方塊。

  3. 點選「刪除」。

刪除虛擬私人雲端網路

如要刪除 VPC 網路:

主控台

  1. 在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。

    前往「VPC networks」(虛擬私有雲網路)

  2. 按一下虛擬私有雲網路的名稱,顯示其「VPC network details」(虛擬私有雲網路詳細資料) 頁面。

  3. 按一下「刪除虛擬私有雲網路」

  4. 在出現的訊息中,按一下 [Delete] (刪除) 完成確認。

後續步驟

如要進一步瞭解虛擬私人雲端網路對等互連,請參閱: