對等互連兩個虛擬私有雲網路
瞭解如何使用 Google Cloud 控制台對等互連兩個虛擬私有雲 (VPC) 網路。
假設有一個機構 organization-a
需要在 project-a
中的 network-a
和 project-b
中的 network-b
之間建立虛擬私有雲網路對等互連。如要成功建立虛擬私有雲網路對等互連,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.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
-
Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
- 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
-
In the Google Cloud console, go to the IAM page.
前往「身分與存取權管理」頁面 - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。
- 在「請選擇角色」清單中,選取角色。
- 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
- 按一下 [Save]。
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Compute Engine API.
-
Make sure that you have the following role or roles on the project: Compute Network Admin or Project Editor
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
- 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
-
In the Google Cloud console, go to the IAM page.
前往「身分與存取權管理」頁面 - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。
- 在「請選擇角色」清單中,選取角色。
- 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
- 按一下 [Save]。
-
- 針對第二個專案重複執行這些步驟。本快速入門說明如何對等互連位於不同專案中的虛擬私有雲網路。
建立兩個虛擬私有雲網路
在本節中,您會建立兩個 VPC 網路,每個網路都位於不同的專案中。
在第一個專案中建立 network-a
和 subnet-a
主控台
在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。
按一下「建立虛擬私有雲網路」。
在「Name」(名稱) 欄位中輸入
network-a
。在「New subnet」(新的子網路) 區段中,指定下列項目:
- 在「Name」(名稱) 欄位中輸入
subnet-a
。 - 選取任一區域。
- 在「IPv4 範圍」欄位中輸入
10.0.1.0/24
。 - 按一下 [完成]。
- 在「Name」(名稱) 欄位中輸入
在「IPv4 防火牆規則」分頁中,點選包含名為
NETWORK-allow-custom
的預先定義輸入防火牆規則的列右側的「編輯」。- 取消選取「使用子網路的 IPv4 範圍」。
- 在「Other IPv4 ranges」(其他 IPv4 範圍) 中輸入
10.0.0.0/20
。輸入這個範圍可確保對等網路中的資源可以彼此通訊,並讓您日後新增更多子網路,而無須更新防火牆規則。 - 按一下「確認」。
按一下 [建立]。
在第二個專案中建立 network-b
和 subnet-b
主控台
在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。
按一下「建立虛擬私有雲網路」。
在「Name」(名稱) 欄位中輸入
network-b
。在「New subnet」(新的子網路) 區段中,指定下列項目:
- 在「Name」(名稱) 欄位中輸入
subnet-b
。 - 選取任一區域。
- 在「IPv4 範圍」欄位中輸入
10.0.8.0/24
。 - 按一下 [完成]。
- 在「Name」(名稱) 欄位中輸入
在「IPv4 防火牆規則」分頁中,點選包含名為
NETWORK-allow-custom
的預先定義輸入防火牆規則的列右側的「編輯」。- 取消選取「使用子網路的 IPv4 範圍」。
- 在「Other IPv4 ranges」(其他 IPv4 範圍) 中輸入
10.0.0.0/20
。輸入這個範圍可確保對等網路中的資源可以彼此通訊,並讓您日後新增更多子網路,而無須更新防火牆規則。 - 按一下「確認」。
按一下 [建立]。
同類應用程式 network-a
與 network-b
在本節中,您將設定 network-a
與 network-b
建立對等連線。
主控台
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
點選「建立連線」。
按一下「繼續」。
針對連線的這一端輸入
peer-ab
做為「Name」(名稱)。在「您的 VPC 網路」下方,選取
network-a
。將「對等互連虛擬私有雲網路」圓形按鈕設為
In another project
。指定其他專案的「Project ID」(專案 ID)。
指定另一個網路 (
network-b
) 的「VPC 網路名稱」。選取「Import custom routes」(匯入自訂路徑) 和「Export custom routes」(匯出自訂路徑)。
按一下 [建立]。
此時,對等互連狀態仍然是 INACTIVE
,因為在 project-b
的 network-b
中沒有相符的設定。
當對等互連狀態變成 ACTIVE
時,VPC 網路對等互連會自動交換子網路路徑。 Google Cloud 也會透過對等互連連線匯入或匯出自訂路徑 (靜態路徑和動態路徑),以交換這些路徑。網路的兩端都必須設定為交換自訂路徑,才能共用這些路徑。詳情請參閱「匯入並匯出自訂路徑」。
若要查看目前的對等互連狀態,請查看對等互連連線:
主控台
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
選取
peer-ab
。在「對等互連連線詳細資料」頁面上,狀態顯示為Inactive. Waiting for the connection to be created by network-b
。
同類應用程式 network-b
與 network-a
在本節中,您會建立從 network-b
到 network-a
的對等互連設定,讓兩端的互連變成 ACTIVE
。
主控台
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
點選「建立連線」。
按一下「繼續」。
針對連線的這一端輸入
peer-ba
做為「Name」(名稱)。在「Your VPC network」(您的 VPC 網路) 底下,選取
network-b
。將「對等互連虛擬私有雲網路」圓形按鈕設為
In another project
。指定其他專案的「Project ID」(專案 ID)。
指定另一個網路 (
network-b
) 的「VPC 網路名稱」。選取「Import custom routes」(匯入自訂路徑) 和「Export custom routes」(匯出自訂路徑)。
按一下 [建立]。
VPC 網路對等互連變成 ACTIVE
一旦對等互連變成 ACTIVE
狀態,子網路路徑和自訂路徑便會交換,允許流量在網路資源之間流動。
主控台
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
在「VPC 網路對等互連」頁面中,您建立的連線狀態會顯示
ACTIVE
。前往另一個專案中的「VPC Network Peering」(VPC 網路對等互連) 頁面,確認狀態是否也顯示
ACTIVE
。
您現在可在 VPC 網路節點看到對等網路 CIDR 前置字串的路徑。這些路徑是為啟用的對等互連連線而產生的隱含路徑,並且沒有對應的路徑資源。下列程序會列出 project-a
所有虛擬私有雲網路的路徑。
主控台
前往 Google Cloud 控制台的「Routes」(路徑) 頁面。
在「Network」(網路) 和「Region」(區域) 中,選取
network-a
和您建立subnet-a
的區域,然後按一下「View」(查看)。在路徑清單中,
subnet-b
有Peering subnet
路徑。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。
刪除專案
如要刪除您建立的專案,請按照下列步驟操作:
- 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.
刪除個別資源
如果您不想刪除整個專案,請刪除 VPC 網路對等互連連線和您建立的 VPC 網路。
您必須先刪除網路的 VPC 網路對等互連連線,才能刪除網路。
刪除 VPC 網路對等互連連線
如要刪除 VPC 網路對等互連連線,請按照下列步驟操作:
主控台
在 Google Cloud 控制台中,前往「VPC Network Peering」(VPC 網路對等互連) 頁面。
找出您要移除的對等互連,並選取旁邊的核取方塊。
點選「刪除」。
刪除虛擬私人雲端網路
如要刪除 VPC 網路:
主控台
在 Google Cloud 控制台中,前往「VPC Networks」(虛擬私有雲網路) 頁面。
按一下虛擬私有雲網路的名稱,顯示其「VPC network details」(虛擬私有雲網路詳細資料) 頁面。
按一下「刪除虛擬私有雲網路」。
在出現的訊息中,按一下 [Delete] (刪除) 完成確認。
後續步驟
如要進一步瞭解虛擬私人雲端網路對等互連,請參閱: