根據預設,每個運算執行個體至少有一個網路介面 (vNIC),可決定執行個體使用的虛擬私有雲網路。您可以建立具有多個網路介面的執行個體。除了使用 RDMA 網路設定檔建立的虛擬私有雲網路外,每個網路介面都必須指派給不重複虛擬私有雲網路中的子網路。網路介面的堆疊類型和子網路的堆疊類型會共同運作,詳情請參閱「堆疊類型和 IP 位址」一文。
每個運算執行個體都會收到預設路徑 (使用 DHCP 選項 121,如 RFC 3442 所定義)。預設路徑與 nic0
相關聯。除非您手動設定,否則流量從執行個體傳送至直接連線的子網路以外的任何目的地時,都會透過 nic0
的預設路徑傳出執行個體。
在 Linux 系統上,您可以使用 /etc/iproute2/rt_tables
檔案和 ip rule
與 ip route
指令,在客體 OS 中設定自訂規則和路徑。詳情請參閱客體 OS 說明文件。如需範例,請參閱「為額外介面設定路由」教學課程。
如果您不需要多個網路介面,請按照建立及啟動執行個體的程序,建立具有預設網路設定的執行個體。
事前準備
- 建立運算執行個體前,請先確認已建立所有必要的網路和子網路。如需建立網路或子網路,請參閱「建立及管理虛擬私有雲網路」。
- 確認每個網路都有適當的防火牆規則,允許資料傳輸至/自具有多個介面的執行個體。如需建立防火牆規則,請參閱「使用虛擬私有雲防火牆規則」。
-
如果使用 IPv6 位址將執行個體連線至多個網路,請安裝
google-guest-agent
版本 20220603.00 以上版本。詳情請參閱「我無法連線至次要介面的 IPv6 位址」。 -
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
必要的角色
如要取得使用特定子網路建立執行個體所需的權限,請要求管理員授予您專案的 Compute Instance 管理員 (v1) (
roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色具備使用特定子網路建立執行個體所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要使用特定子網路建立執行個體,必須具備下列權限:
-
專案的
compute.instances.create
-
如要為執行個體指定子網路:
compute.subnetworks.use
專案或所選子網路的 -
使用虛擬私有雲網路時,如要將外部 IP 位址指派給執行個體,請在專案或所選子網路上授予
compute.subnetworks.useExternalIp
權限。
需求條件
建立具備多個網路介面的執行個體前,請先查看下列規定:
- 除非是使用 RDMA 網路設定檔建立的 VPC 網路,否則適用下列限制:如果您建立具有多個網路介面的執行個體,每個介面都必須連線至不同的 VPC 網路。這些網路可以是獨立的虛擬私有雲網路,也可以是共用虛擬私有雲網路。
- 每個網路介面都必須使用不重複的子網路 IP 位址範圍。
- 如果是獨立專案中的多 NIC 運算執行個體,每個網路介面都必須使用與執行個體位於相同專案的子網路。如要瞭解共用虛擬私有雲主機或服務專案中的執行個體,請參閱虛擬私有雲說明文件中的「共用虛擬私有雲 」。Private Service Connect 介面可讓多 NIC 執行個體在不同專案的子網路中擁有網路介面。詳情請參閱「關於網路連結」。
建立具備多個網路介面的 VM 執行個體
建立執行個體時,您可以在大多數 Compute Engine 執行個體中設定多個虛擬 NIC。
如要瞭解如何建立具備多個網路介面的運算執行個體,請參閱「建立具備多個網路介面的 VM 執行個體」。
將網路介面新增至現有執行個體
您只能在建立執行個體時,為執行個體設定虛擬 NIC (vNIC)。不過,您可以為現有執行個體新增或移除動態 NIC,且不必重新啟動執行個體。
Dynamic NIC 是上層 vNIC 的子介面。 設定動態 NIC 時,請指定用於標記動態 NIC 網路流量的 VLAN ID:
- Dynamic NIC 的 VLAN ID 必須是介於 2 至 255 之間的整數。
- Dynamic NIC 的 VLAN ID 在上層 vNIC 中不得重複。不過,屬於不同上層 vNIC 的 Dynamic NIC 可以使用相同的 VLAN ID。
Trusted Cloud by S3NS 會使用下列格式做為動態 NIC 的名稱:
PARENT_NIC_NUMBER.VLAN_ID
PARENT_NIC_NUMBER
是父項 vNIC 的名稱,例如nic0
。VLAN_ID
是您在設定動態 NIC 時指定的號碼。動態 NIC 名稱範例為nic0.4
。如要瞭解如何將動態 NIC 新增至執行個體,請參閱「將動態 NIC 新增至執行個體」。
後續步驟
- 瞭解如何使用 SSH 連線連線至執行個體。
- 使用內部 DNS 存取 VM
- 建立 VM 執行個體的 PTR 記錄
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-18 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-18 (世界標準時間)。"],[],[],null,["# Create VMs with multiple network interfaces\n\n*** ** * ** ***\n\nBy default, every compute instance has at least one network interface (vNIC)\nthat determines the Virtual Private Cloud network that the instance uses. You can\ncreate an instance with multiple network interfaces. Except for\nVPC networks that are created with an RDMA network profile, each\nnetwork interface must be assigned to a subnet in a unique VPC\nnetwork. The stack type of the network interface and the stack type of the\nsubnet work together as described in\n[Stack types and IP addresses](/vpc/docs/multiple-interfaces-concepts#stack-types)\n\nEach compute instance receives a default route using DHCP Option 121, as defined\nby [RFC 3442](https://datatracker.ietf.org/doc/html/rfc3442). The default route\nis associated with `nic0`. Unless manually configured otherwise, any traffic\nleaving an instance for any destination other than a directly connected subnet\nleaves the instance using the default route on `nic0`.\n\nOn Linux systems, you can configure custom rules and routes within the guest OS\nusing the `/etc/iproute2/rt_tables` file and the `ip rule` and `ip route`\ncommands. For more information, consult the guest OS documentation. For an\nexample, see the tutorial\n[Configure routing for an additional interface](/vpc/docs/configure-routing-additional-interface).\n\nIf you don't require multiple network interfaces, follow the procedure for\n[creating and starting an instance](/compute/docs/instances/create-start-instance)\nto create instances with the default network configuration.\n\nBefore you begin\n----------------\n\n- Verify that all required networks and subnets are created before you create the compute instance. If you need to create networks or subnets, see [Create and manage\n VPC networks](/vpc/docs/create-modify-vpc-networks).\n- Verify that each network has appropriate firewall rules that let data transfer to and from the instance that has multiple interfaces. If you need to create firewall rules, see [Use VPC firewall rules](/firewall/docs/using-firewalls).\n- If you are [connecting an\n instance to multiple networks by using IPv6 addresses](/vpc/docs/create-use-multiple-interfaces#example-dual), then install the `google-guest-agent` version [20220603.00](https://github.com/GoogleCloudPlatform/guest-agent/releases/tag/20220603.00) or later. For more information, see [I can't\n connect to a secondary interface's IPv6 address](/vpc/docs/troubleshoot-multiple-interfaces#connect-ipv6).\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n ### REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\n### Required roles\n\n\nTo get the permissions that\nyou need to create an instance with a specific subnet,\n\nask your administrator to grant you the\n\n\n[Compute Instance Admin (v1)](/iam/docs/roles-permissions/compute#compute.instanceAdmin.v1) (`roles/compute.instanceAdmin.v1`)\nIAM role on the project.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nThis predefined role contains\n\nthe permissions required to create an instance with a specific subnet. To see the exact permissions that are\nrequired, expand the **Required permissions** section:\n\n\n#### Required permissions\n\nThe following permissions are required to create an instance with a specific subnet:\n\n- ` compute.instances.create` on the project\n- To specify a subnet for your instance: ` compute.subnetworks.use` on the project or on the chosen subnet\n- To assign an external IP address to the instance when using a VPC network: ` compute.subnetworks.useExternalIp` on the project or on the chosen subnet\n\n\nYou might also be able to get\nthese permissions\nwith [custom roles](/iam/docs/creating-custom-roles) or\nother [predefined roles](/iam/docs/roles-overview#predefined).\n\nRequirements\n------------\n\nBefore you create an instance with multiple network interfaces, review the\nfollowing requirements:\n\n- Except for VPC networks that are created with an [RDMA network profile](/vpc/docs/rdma-network-profiles), the following limitation applies: If you create an instance with multiple network interfaces, each interface must connect to a different VPC network. The networks can be standalone [VPC networks](/vpc/docs/vpc) or [Shared VPC networks](/vpc/docs/shared-vpc).\n- Each network interface must use a unique subnet IP address range.\n- For multi-NIC compute instances in standalone projects, each network interface must use a subnet located in the same project as the instance. For instances in Shared VPC host or service projects, see [Shared VPC](/vpc/docs/multiple-interfaces-concepts#multiple-network-interfaces-in-shared-vpc) in the Virtual Private Cloud documentation. [Private Service Connect interfaces](/vpc/docs/about-private-service-connect-interfaces) provide a way for a multi-NIC instance to have network interfaces in subnets in different projects. For more information, see [About network attachments](/vpc/docs/about-network-attachments).\n\nCreate VM instances with multiple network interfaces\n----------------------------------------------------\n\nMost Compute Engine instances let you configure multiple vNICs when\ncreating the instance.\n\n- For information about the number of network interfaces you can create for an instance, see [Maximum number of network interfaces](/vpc/docs/multiple-interfaces-concepts#max-interfaces).\n- You can also configure [Dynamic NICs](/vpc/docs/multiple-interfaces-concepts#nic-types) when creating an instance.\n\nFor information about how to create a compute instance with multiple network\ninterfaces, see\n[Create VM instances with multiple network interfaces](/vpc/docs/create-use-multiple-interfaces#creating_virtual_machine_instances_with_multiple_network_interfaces).\n\nAdd network interfaces to an existing instance\n----------------------------------------------\n\nYou can configure virtual NICs (vNICs) for an instance only when creating the\ninstance. However, you can add or remove\n[Dynamic NICs](/vpc/docs/multiple-interfaces-concepts#nic-types)\nto an existing instance, and you don't have to restart the instance.\n\nDynamic NICs are subinterfaces of a parent vNIC.\nWhen you configure a Dynamic NIC, you specify\na VLAN ID that is used to tag network traffic for the\nDynamic NIC:\n\n- The VLAN ID of a Dynamic NIC must be an integer from 2 to 255.\n- The VLAN ID of a Dynamic NIC must be unique within a parent vNIC. However, Dynamic NICs that belong to different parent vNICs can use the same VLAN ID.\n\nGoogle Cloud uses the following format for the name of a\nDynamic NIC:\n\u003cvar translate=\"no\"\u003ePARENT_NIC_NUMBER\u003c/var\u003e`.`\u003cvar translate=\"no\"\u003eVLAN_ID\u003c/var\u003e\n\n\u003cvar translate=\"no\"\u003ePARENT_NIC_NUMBER\u003c/var\u003e is the name of the parent vNIC, for example\n`nic0`. The \u003cvar translate=\"no\"\u003eVLAN_ID\u003c/var\u003e is the number you specified when\nconfiguring the Dynamic NIC. An example\nDynamic NIC name is `nic0.4`.\n\nFor information about how to add Dynamic NICs to an\ninstance, see\n[Add Dynamic NICs to an instance](/vpc/docs/add-dynamic-nics).\n\nWhat's next?\n------------\n\n- Learn how to use [SSH connections](/compute/docs/instances/ssh) to connect to your instance.\n- [Access VMs using internal DNS](/compute/docs/networking/using-internal-dns)\n- [Create a PTR record for a VM instance](/compute/docs/instances/create-ptr-record)"]] -