Create VMs with multiple network interfaces (original) (raw)

Skip to main content

This page describes how to create VM instances with multiple network interfaces.

Before you begin

Before you begin, ensure that you're familiar with the characteristics of instances with multiple network interfaces as described in theMultiple network interfaces overview.

IAM roles

To create an instance with multiple network interfaces, you must have one of the following roles:

Creating and deleting instances and instance templates with multiple interfaces in a project not using a Shared VPC environment: A user with the Owner, Editor, or Compute Instance Admin (v1) role can create an instance with multiple interfaces associated with VPC networks and subnets that are part of that same project.

**Creating and deleting instances and instance templates with multiple interfaces in Shared VPC environments:**A user with the Owner, Editor, or Compute Instance Admin (v1) role can create an instance with multiple interfaces. If any of the interfaces are attached to a subnet in a Shared VPC host project, you must also have theCompute Network User role (roles/compute.networkUser) for the whole host project or for the subnets you need to use.

To learn more about permissions, read theCompute Engine IAM documentation.

Create VM instances with multiple network interfaces

This section describes how to create an instance with multiple network interfaces, including vNICs and Dynamic NICs. For general instructions about creating instances, see Create and start a VM instance.

The first interface is always created as nic0, and it is always the default interface.

Console

  1. In the Google Cloud console, go to the Create an instance page.
    Go to Create an instance
  2. In the Machine configuration pane, do the following:
    1. In the Name field, enter a name for the instance.
    2. In the Region field, select a region.
    3. In the Zone field, select a zone.
  3. In the navigation menu, click Networking to view the Networking pane.
  4. In the Network interfaces section, expand the network interface to edit it.
    1. For Network and Subnetwork, select the network and subnetwork that you want to use.
      If you want to configure IPv6 addresses on the interface, select a subnet that has an /64 IPv6 address range configured. The IPv6 access type of the subnet determines whether the instance receives an internal /96 IPv6 address range or an external /96 IPv6 address range.
    2. Select one of the following options for the IP stack type for the interface:
      • IPv4 (single-stack)
      • IPv4 and IPv6 (dual-stack)
      • IPv6 (single-stack)
    3. For interfaces with IPv4 addresses, do the following:
      1. For Primary internal IPv4 address, select one of the following:
        * Ephemeral (Automatic) to automatically assign a new ephemeral IPv4 address
        * Ephemeral (Custom) to manually specify a new ephemeral IPv4 address
        * A reserved static internal IPv4 address from the list
        * Reserve static internal IPv4 address to reserve and assign a new static internal IPv4 address
      2. For External IPv4 address, select one of the following:
        * Ephemeral to assign a new ephemeral IPv4 address
        * None to not assign an external IPv4 address
        * A reserved static IPv4 address from the list
        * Reserve static external IP address to reserve and assign a new static external IPv4 address
      3. You can optionally assign one or morealias IP ranges to the network interface. To assign an alias IP range, do the following:
        1. In Alias IP ranges, clickAdd IP range.
        2. In Subnet range, select a subnet primary IPv4 address range or a subnet secondary IPv4 address range to use.
        3. For Alias IP range, enter an IP range in CIDR notation. This range must be an unused range of the subnet IP range that you selected.

      For more information about assigning alias IP ranges to VM network interfaces, see Configure alias IP ranges.

    4. For interfaces with IPv6 addresses, do the following, depending on the access type of the connected subnet:
      1. For Primary internal IPv6 address, select one of the following:
        * Ephemeral (Automatic) to automatically assign a new ephemeral internal IPv6 address range
        * Ephemeral (Custom) to manually specify a new ephemeral internal IPv6 address range
        * A reserved static internal IPv6 address range from the list
        * Reserve static internal IPv6 address to reserve and assign a new static internal IPv6 address range
      2. For External IPv6 address, select one of the following:
        * Ephemeral (Automatic) to automatically assign a new ephemeral external IPv6 address range
        * Ephemeral (Custom) to manually specify a new ephemeral external IPv6 address range
        * A reserved static external IPv6 address range from the list
        * Reserve static external IPv6 address to reserve and assign a new static external IPv6 address range
    5. To finish modifying the network interface, click Done.
  5. To add another network interface:
    1. To add a vNIC, click Add a network interface and complete the form by entering the details of the vNIC.
    2. To add a Dynamic NIC, click Add a Dynamic Network Interfaceand do the following:
      1. In the Parent network interface field, select the parent vNIC for which to create the Dynamic NIC.
      2. In the VLAN ID field, enter the VLAN ID of the Dynamic NIC.
      3. Complete the form by entering the remaining details of the Dynamic NIC.
  6. Continue with the instance creation process.
  7. Click Create.

gcloud

To create network interfaces on a new instance, use thegcloud compute instances create command.

Include the --network-interface flag for each interface, followed by any appropriate networking keys, such asnetwork, subnet, private-network-ip, address, external-ipv6-addressand vlan.

Including the vlan key creates a Dynamic NIC. If you create a Dynamic NIC, you must also follow the steps for configuring the guest OS for Dynamic NICsafter you create the instance.

To view examples of how to create instances with multiple interfaces, see example configurations.

This snippet only illustrates the --network-interface flag, one of many possible parameters that you can specify when creating an instance.

gcloud compute instances create INSTANCE_NAME
--zone ZONE
--network-interface
network=NETWORK_A,subnet=SUBNET_A,
stack-type=STACK_TYPE,
private-network-ip=INTERNAL_IPV4_ADDRESS,
address=EXTERNAL_IPV4_ADDRESS | no-address,
internal-ipv6-address=INTERNAL_IPV6_ADDRESS
... --network-interface
network=NETWORK_B,subnet=SUBNET_B,
stack-type=STACK_TYPE,
external-ipv6-address=EXTERNAL_IPV6_ADDRESS,
external-ipv6-prefix-length=96,
ipv6-network-tier=PREMIUM,
vlan=VLAN_ID
...

Replace the following:

API

Use the instances.insert methodto create an instance with multiple network interfaces.

Including the vlan field creates a Dynamic NIC. If you create a Dynamic NIC, you must also follow the steps for configuring the guest OS for Dynamic NICsafter you create the instance.

See the following examples:

Terraform

You can use a Terraform resourceto create an instance with multiple network interfaces.

The Terraform arguments have example values that you can change.

To learn how to apply or remove a Terraform configuration, seeBasic Terraform commands.

Example configurations

The following sections show how to create instances with multiple interfaces.

Configure multiple vNICs and Dynamic NICs

The following sample command creates an instance with the following network interfaces:

gcloud compute instances create vm1
--zone zone-a
--network-interface=network=network-a,subnet=subnet-a
--network-interface=network=network-b,subnet=subnet-b,vlan=2
--network-interface=network=network-c,subnet=subnet-c
--network-interface=network=network-d,subnet=subnet-d,vlan=4
--network-interface=network=network-e,subnet=subnet-e,vlan=5

After you create an instance with Dynamic NICs, you must alsoconfigure the guest OS for Dynamic NICs.

Configure multiple network interfaces with only IPv4 addresses

The following sample command creates an instance with three network interfaces.

gcloud compute instances create vm1 --machine-type=n1-standard-4
--network-interface ''
--network-interface network=net1,subnet=subnet-a,private-network-ip=10.10.10.2,address=EXTERNAL_IPV4_ADDRESS
--network-interface network=net2,subnet=subnet-b,private-network-ip=10.10.20.2,no-address

The interfaces are created as follows:

For a complete description of the gcloud compute instances createcommand and the --network-interface flag, read the documentation for the command.

You can use the IP address from the network interface that you have added to set up DNS forwarding. To learn more about configuring Cloud DNS forwarding zones, see Forwarding zones.

Configure multiple network interfaces with both IPv4 and IPv6 addresses

The following sample command creates a dual-stack instance with two network interfaces.

gcloud compute instances create vm1
--network-interface network=dual-int,subnet=int-subnet,stack-type=IPV4_IPV6
--network-interface network=dual-ext,subnet=ext-subnet,stack-type=IPV4_IPV6,ipv6-network-tier=PREMIUM
--machine-type=n1-standard-4 --zone=ZONE_A

The interfaces are created as follows:

Configure multiple network interfaces with only IPv6 addresses

The following sample command creates an IPv6-only instance with three network interfaces.

gcloud compute instances create vm1
--network-interface network=ipv6-only-int-a,subnet=int-subnet-a,stack-type=IPV6_ONLY
--network-interface network=ipv6-only-int-b,subnet=int-subnet-b,stack-type=IPV6_ONLY,internal-ipv6-address=fd20:db8:0:0:1:0::
--network-interface network=ipv6-only-ext,subnet=ext-subnet,stack-type=IPV6_ONLY,ipv6-network-tier=PREMIUM,external-ipv6-address=EXTERNAL_IPV6_ADDRESS
--machine-type=n1-standard-4 --zone=us-west2-a

The interfaces are created as follows:

Configure multiple network interfaces for instance groups

You can use instances with multiple network interfaces in unmanaged instance groups and managed instance groups.

For unmanaged instance groups,create each instance individually, ensuring that the nic0 network interface for each instance is attached to the same subnet. Then, add the instances to the unmanaged instance group.

To configure multiple network interfaces formanaged instance groups, you must specify the network configuration for each interface in the instance template, by setting the --network-interface flag once for each interface. The following sample creates an instance template with three network interfaces:

gcloud compute instance-templates create template-1
--network-interface subnet=net0-subnet-a
--network-interface subnet=net1-subnet-b,no-address
--network-interface subnet=net2-subnet-c,no-address
--region REGION_A

Because subnet names in each region of a project must be unique, specifying subnets by name implicitly associates each interface with a VPC network. In this example, each interface uses a subnet that is in a unique VPC network:

The no-address option in the --network-interface flag indicates that the interface is configured without an external IPv4 address. The internal IP address comes from the subnet used by the interface. For complete information about the flags and syntax, see the--network-interface flag for the instance-templates createcommand.

What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-06-15 UTC.