Create VMs with multiple network interfaces


By default, every compute instance has at least one network interface (vNIC) that determines the Virtual Private Cloud network that the instance uses. You can create an instance with multiple network interfaces. Except for VPC networks that are created with an RDMA network profile, each network interface must be assigned to a subnet in a unique VPC network. The stack type of the network interface and the stack type of the subnet work together as described in Stack types and IP addresses

Each compute instance receives a default route using DHCP Option 121, as defined by RFC 3442. The default route is associated with nic0. Unless manually configured otherwise, any traffic leaving an instance for any destination other than a directly connected subnet leaves the instance using the default route on nic0.

On Linux systems, you can configure custom rules and routes within the guest OS using the /etc/iproute2/rt_tables file and the ip rule and ip route commands. For more information, consult the guest OS documentation. For an example, see the tutorial Configure routing for an additional interface.

If you don't require multiple network interfaces, follow the procedure for creating and starting an instance to create instances with the default network configuration.

Before you begin

Required roles

To get the permissions that you need to create an instance with a specific subnet, ask your administrator to grant you the Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1) IAM role on the project. For more information about granting roles, see Manage access to projects, folders, and organizations.

This predefined role contains the permissions required to create an instance with a specific subnet. To see the exact permissions that are required, expand the Required permissions section:

Required permissions

The following permissions are required to create an instance with a specific subnet:

  • compute.instances.create on the project
  • To specify a subnet for your instance: compute.subnetworks.use on the project or on the chosen subnet
  • 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

You might also be able to get these permissions with custom roles or other predefined roles.

Requirements

Before you create an instance with multiple network interfaces, review the following requirements:

  • Except for VPC networks that are created with an RDMA network profile, 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 or Shared VPC networks.
  • Each network interface must use a unique subnet IP address range.
  • 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 in the Virtual Private Cloud documentation. 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.

Create VM instances with multiple network interfaces

Most Compute Engine instances let you configure multiple vNICs when creating the instance.

For information about how to create a compute instance with multiple network interfaces, see Create VM instances with multiple network interfaces.

Add network interfaces to an existing instance

You can configure virtual NICs (vNICs) for an instance only when creating the instance. However, you can add or remove Dynamic NICs to an existing instance, and you don't have to restart the instance.

Dynamic NICs are subinterfaces of a parent vNIC. When you configure a Dynamic NIC, you specify a VLAN ID that is used to tag network traffic for the Dynamic NIC:

  • The VLAN ID of a Dynamic NIC must be an integer from 2 to 255.
  • 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.

Google Cloud uses the following format for the name of a Dynamic NIC: PARENT_NIC_NUMBER.VLAN_ID

PARENT_NIC_NUMBER is the name of the parent vNIC, for example nic0. The VLAN_ID is the number you specified when configuring the Dynamic NIC. An example Dynamic NIC name is nic0.4.

For information about how to add Dynamic NICs to an instance, see Add Dynamic NICs to an instance.

What's next?