建立兩個虛擬私有雲網路的對等互連
在本快速入門導覽課程中,您將瞭解如何使用 Google Cloud 控制台,對等互連兩個虛擬私有雲 (VPC) 網路。
假設有一個機構需要在 project-a 中的 network-a 與 project-b 中的 network-b 之間,建立虛擬私有雲網路對接。organization-a如要成功建立虛擬私有雲網路對等互連,network-a 和 network-b 的管理員必須個別設定對等互連關聯。
完成本頁的步驟後,您將建立下列設定:
對等互連連線處於獨立模式 (預設)。
事前準備
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
如要使用現有專案進行本指南中的操作,請確認您具有所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
如要使用現有專案進行本指南中的操作,請確認您具有所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. - 針對第二個專案重複上述步驟。本快速入門導覽說明如何對等互連不同專案中的虛擬私有雲網路。
-
Compute 網路管理員 (
roles/compute.networkAdmin) -
Compute 安全管理員 (
roles/compute.securityAdmin) 前往 Google Cloud 控制台的「VPC Networks」(虛擬私有雲網路) 頁面。
按一下「建立虛擬私有雲網路」。
在「Name」(名稱) 欄位中,輸入
network-a。在「New subnet」(新的子網路) 區段中,指定下列項目:
- 在「Name」(名稱) 欄位中,輸入
subnet-a。 - 選取任一區域。
- 在「IPv4 range」(IPv4 範圍) 欄位中,輸入
10.0.1.0/24。 - 按一下 [完成]。
- 在「Name」(名稱) 欄位中,輸入
在「IPv4 防火牆規則」分頁中,找到包含名為
NETWORK-allow-custom的預先定義輸入防火牆規則的資料列,然後點選右側的「編輯」。- 取消選取「使用子網路的 IPv4 範圍」。
- 在「Other IPv4 ranges」(其他 IPv4 範圍) 中,輸入
10.0.0.0/20。輸入這個範圍可確保對等網路中的資源能夠彼此通訊,並讓您在日後新增更多子網路時,不必更新防火牆規則。 - 按一下「確認」。
點選「建立」。
前往 Google Cloud 控制台的「VPC Networks」(虛擬私有雲網路) 頁面。
按一下「建立虛擬私有雲網路」。
在「Name」(名稱) 欄位中,輸入
network-b。在「New subnet」(新的子網路) 區段中,指定下列項目:
- 在「Name」(名稱) 欄位中,輸入
subnet-b。 - 選取任一區域。
- 在「IPv4 range」(IPv4 範圍) 欄位中,輸入
10.0.8.0/24。 - 按一下 [完成]。
- 在「Name」(名稱) 欄位中,輸入
在「IPv4 防火牆規則」分頁中,找到包含名為
NETWORK-allow-custom的預先定義輸入防火牆規則的資料列,然後點選右側的「編輯」。- 取消選取「使用子網路的 IPv4 範圍」。
- 在「Other IPv4 ranges」(其他 IPv4 範圍) 中,輸入
10.0.0.0/20。輸入這個範圍可確保對等網路中的資源能夠彼此通訊,並讓您在日後新增更多子網路時,不必更新防火牆規則。 - 按一下「確認」。
點選「建立」。
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
點選「建立連線」。
按一下「繼續」。
針對連線的這一端輸入
peer-ab做為「Name」(名稱) 。在「Your VPC network」(您的 VPC 網路) 底下,選取
network-a。將「對等互連虛擬私有雲網路」圓形按鈕設為
In another project。指定其他專案的「Project ID」(專案 ID)。
指定另一個網路的「VPC 網路名稱」,即
network-b。選取「匯入自訂路徑」和「匯出自訂路徑」。
點選「建立」。
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
選取「
peer-ab」。在「對等互連連線詳細資料」頁面上,狀態會顯示Inactive. Waiting for the connection to be created by network-b。在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
點選「建立連線」。
按一下「繼續」。
針對連線的這一端輸入
peer-ba做為「Name」(名稱) 。在「您的虛擬私有雲網路」下方,選取
network-b。將「對等互連虛擬私有雲網路」圓形按鈕設為
In another project。指定其他專案的「Project ID」(專案 ID)。
指定另一個網路的「VPC 網路名稱」,即
network-b。選取「匯入自訂路徑」和「匯出自訂路徑」。
點選「建立」。
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
在「VPC 網路對等互連」頁面中,您建立的連線狀態會顯示
ACTIVE。前往另一個專案中的「VPC 網路對等互連」頁面,確認狀態是否也顯示
ACTIVE。前往 Google Cloud 控制台的「Routes」(路徑) 頁面。
在「網路」和「區域」中,選取
network-a和您建立subnet-a的區域,然後按一下「查看」。在路徑清單中,有一個
Peering subnet的subnet-b路徑。- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
找出您要移除的對等互連,並選取旁邊的核取方塊。
按一下「Delete」(刪除)。
前往 Google Cloud 控制台的「VPC Networks」(虛擬私有雲網路) 頁面。
按一下虛擬私有雲網路的名稱,顯示其「VPC network details」(虛擬私有雲網路詳細資料) 頁面。
按一下「刪除虛擬私有雲網路」。
在出現的訊息中,按一下 [Delete] (刪除) 完成確認。
必要的角色
如要取得對等互連兩個虛擬私有雲網路所需的權限,請要求管理員在專案中授予您下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
建立兩個虛擬私有雲網路
在本節中,您將建立兩個虛擬私有雲網路,分別位於不同的專案中。
在第一個專案中建立 network-a 和 subnet-a
控制台
在第二個專案中建立 network-b 和 subnet-b
控制台
與「network-b」對等互連network-anetwork-b
在本節中,您會將 network-a 設定為與 network-b 對等互連。
控制台
此時,對等互連狀態仍然是 INACTIVE,因為 project-b 的 network-b 中沒有相符的設定。
當對等互連狀態變成 ACTIVE 時,VPC 網路對等互連會自動交換子網路路徑。 Google Cloud 也會透過對等互連連線匯入和匯出自訂路徑 (靜態路徑和動態路徑),以交換這些路徑。網路的兩端都必須設定為交換自訂路徑,才能共用這些路徑。詳情請參閱「匯入並匯出自訂路徑」。
若要查看目前的對等互連狀態,請查看對等互連連線:
控制台
與「network-a」對等互連network-bnetwork-a
在本節中,您將從 network-b 建立相符的對等互連設定到 network-a,以便在兩端都建立對等互連 ACTIVE。
控制台
虛擬私有雲網路對等互連變成 ACTIVE
對等互連進入 ACTIVE 狀態時,系統就會交換子網路路由和自訂路由,讓網路中的資源可以互通流量。
控制台
您現在可在 VPC 網路節點看到對等網路 CIDR 前置字串的路徑。這些路徑是為啟用的對等互連連線而產生的隱含路徑,並且沒有對應的路徑資源。下列程序會列出 project-a 所有虛擬私有雲網路的路徑。
控制台
清除所用資源
為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。
刪除專案
如要刪除您建立的專案,請按照下列步驟操作:
刪除個別資源
如果不想刪除整個專案,請刪除您建立的虛擬私有雲網路對等互連連線和虛擬私有雲網路。
如要刪除網路,必須先刪除其虛擬私有雲網路對等互連連線。
刪除虛擬私有雲網路對等互連連線
如要刪除 VPC 網路對等互連連線:
控制台
刪除虛擬私人雲端網路
如要刪除 VPC 網路: