Create and manage VPC networks
This document describes how to create, modify, and delete Virtual Private Cloud (VPC) networks and subnetworks. Before reading this document, ensure that you are familiar with the characteristics of VPC networks as described in VPC networks. Networks and subnets are different resources in Google Cloud.
If you plan to enable IPv6 ranges on subnets, see IPv6 subnet ranges.
Try it for yourself
If you're new to Google Cloud, create an account to evaluate how VPC performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
Try VPC freeCreate networks
You can choose to create an auto mode or custom mode VPC network. Each new network that you create must have a unique name within the same project.
You can optionally create your network using a network profile provided by Google Cloud for a specific use case. You only need to configure a network profile if you want to run AI Hypercomputer workloads that require RDMA NICs. For more information, see RDMA network profiles.
Create an auto mode VPC network
When you create an auto mode VPC network, one subnet is created in each Google Cloud region. As new regions become available, new subnets in those regions are automatically added to the auto mode VPC network. IPv4 ranges for the automatically created subnets come from a predetermined set of ranges. All auto mode VPC networks use the same set of IPv4 ranges.
Subnets with IPv6 address ranges are not supported on auto mode VPC networks. Create a custom mode VPC network if you want to create subnets with IPv6 address ranges.
To create an auto mode VPC network, follow these steps.
Console
In the Google Cloud console, go to the VPC networks page.
Click Create VPC network.
Enter a Name for the network.
To configure the maximum transmission unit (MTU) of the network, do the following:
- To use the default value of
1460, keep the Set MTU automatically checkbox selected. - To set a custom value, do the following:
- Review the information in Maximum transmission unit.
- Clear the Set MTU automatically checkbox.
- In the Maximum transmission unit (MTU) field, choose an MTU value.
- To use the default value of
Choose Automatic for the Subnet creation mode.
In the Firewall rules section, select zero or more predefined firewall rules. The rules address common use cases for connectivity to instances.
Whether or not you select pre-defined rules, you can create your own firewall rules after you create the network.
Each predefined rule name starts with the name of the VPC network that you are creating,
NETWORK. In the IPv4 firewall rules tab, the predefined ingress firewall rule namedNETWORK-allow-customis editable. By default it specifies the source range10.128.0.0/9, which contains current and future IPv4 ranges for subnets in an auto mode network. The right side of the row that contains the rule, click Edit to select subnets, add additional IPv4 ranges, and specify protocols and ports.Choose the Dynamic routing mode for the VPC network.
For more information, see dynamic routing mode. You can change the dynamic routing mode later.
Click Create.
gcloud
Use the
networks create command.
gcloud compute networks create NETWORK \
--subnet-mode=auto \
--bgp-routing-mode=DYNAMIC_ROUTING_MODE \
--mtu=MTU
Replace the following:
NETWORK: a name for the VPC network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherglobalorregional. The default isregional. For more information, see dynamic routing mode.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
Terraform
Use
the google_compute_network Terraform resource.
MTU is the maximum transmission unit, or largest packet
size, of the network. MTU can be set to any value from 1300 to 8896.
The default is 1460. Before setting the MTU to a
value higher than 1460, review Maximum transmission unit.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
API
Make a POST request to
the networks.insert method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks
{
"autoCreateSubnetworks": true,
"name": "auto-network1",
"mtu": MTU
}Replace the following:
PROJECT_ID: the ID of the project where the VPC network is created.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
To specify the dynamic routing
mode
of the VPC network, include the routingConfig field:
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks
{
"routingConfig": {
"routingMode": "DYNAMIC_ROUTING_MODE"
},
"autoCreateSubnetworks": true,
"name": "NETWORK",
"mtu": MTU
}Replace the following:
PROJECT_ID: the ID of the project where the VPC network is created.NETWORK: a name for the VPC network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherGLOBALorREGIONAL. The default isREGIONAL. For more information, see dynamic routing mode.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
Create a custom mode VPC network with IPv4-only subnets
For custom mode VPC networks, create a network, then create the subnets that you want within a region. You do not have to specify subnets for all regions right away, or even at all, but you cannot create instances in a region that has no subnet defined. Finally, define the firewall rules for your network.
Each subnet in a VPC network can have a different configuration; you don't need to configure them all as IPv4-only, for example. You can also change an IPv4-only only subnet to dual-stack later.
To create a custom mode VPC network with IPv4-only subnets, follow these steps.
Console
In the Google Cloud console, go to the VPC networks page.
Click Create VPC network.
Enter a Name for the network.
To configure the MTU of the network, do the following:
- To use the default value of
1460, keep the Set MTU automatically checkbox selected. - To set a custom value, do the following:
- Review the information in Maximum transmission unit.
- Clear the Set MTU automatically checkbox.
- In the Maximum transmission unit (MTU) field, choose an MTU value.
- To use the default value of
Choose Custom for the Subnet creation mode.
In the New subnet section, specify the following configuration parameters for a subnet:
- Provide a Name for the subnet.
- Select a Region.
Enter an IP address range. This is the primary IPv4 range for the subnet.
If you select a range that is not an RFC 1918 address, confirm that the range doesn't conflict with an existing configuration. For more information, see IPv4 subnet ranges.
To define a secondary range for the subnet, click Create secondary IP range.
If you select a range that is not an RFC 1918 address, confirm that the range doesn't conflict with an existing configuration. For more information, see IPv4 subnet ranges.
Private Google Access: Choose whether to enable Private Google Access for the subnet when you create it or later by editing it.
Flow logs: Choose whether to enable VPC flow logs for the subnet when you create it or later by editing it.
Click Done.
To add more subnets, click Add subnet and repeat the previous steps. You can also add more subnets to the network after you have created the network.
In the Firewall rules section, select zero or more predefined firewall rules in the IPv4 firewall rules. The rules address common use cases for connectivity to instances.
If you don't select any predefined rules, you can create your own firewall rules after you create the network.
Each predefined rule name starts with the name of the VPC network that you are creating,
NETWORK. In the IPv4 firewall rules tab, the predefined ingress firewall rule namedNETWORK-allow-customis editable. On the right side of the row that contains the rule, click Edit to select subnets, add additional IPv4 ranges, and specify protocols and ports.The
NETWORK-allow-customfirewall rule is not automatically updated if you later add additional subnets. If you need firewall rules for the new subnets, you must update the firewall configuration to add the rules.Choose the Dynamic routing mode for the VPC network.
For more information, see dynamic routing mode. You can change the dynamic routing mode later.
Click Create.
gcloud
Use the networks create command.
gcloud compute networks create NETWORK \
--subnet-mode=custom \
--bgp-routing-mode=DYNAMIC_ROUTING_MODE \
--mtu=MTU
Replace the following:
NETWORK: a name for the VPC network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherglobalorregional. The default isregional. For more information, see dynamic routing mode.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
Next, add subnets to your network.
Terraform
Use the google_compute_network Terraform resource.
MTU is the maximum transmission unit, or largest packet
size, of the network. MTU can be set to any value from 1300 to 8896.
The default is 1460. Before setting the MTU to a
value higher than 1460, review Maximum transmission unit.
Next, add subnets to your network.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
API
Make a POST request to the
networks.insert method.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks
{
"autoCreateSubnetworks": false,
"name": "NETWORK",
"mtu": MTU,
"routingConfig": {
"routingMode": "DYNAMIC_ROUTING_MODE"
}
}
Replace the following:
PROJECT_ID: the ID of the project where the VPC network is created.NETWORK: a name for the VPC network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherGLOBALorREGIONAL. The default isREGIONAL. For more information, see dynamic routing mode.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
Next, add subnets to your network.
Create a custom mode VPC network with a dual-stack subnet
You can create subnets when you create the network, or you can add them later.
A dual-stack subnet can have one of the following configurations for its primary IP address ranges:
- Internal IPv4 range and internal IPv6 range
- Internal IPv4 range and external IPv6 range
Each subnet in a VPC network can have a different configuration; you don't need to configure them all as dual-stack, for example.
By default, the addresses for a subnet's IPv6 range are provided by Google. If you want to use BYOIP to bring your own IPv6 addresses, see Assign subnet ranges instead.
Console
In the Google Cloud console, go to the VPC networks page.
Click Create VPC network.
Enter a Name for the network.
To configure the MTU of the network, do the following:
- To use the default value of
1460, keep the Set MTU automatically checkbox selected. - To set a custom value:
- Review the information in Maximum transmission unit.
- Clear the Set MTU automatically checkbox.
- In the Maximum transmission unit (MTU) field, choose an MTU value.
- To use the default value of
For Subnet creation mode, choose Custom.
If you want to configure internal IPv6 address ranges on subnets in this network, complete these steps:
- In the Private IPv6 address settings section, select Configure a ULA internal IPv6 range for this VPC Network.
For Allocate internal IPv6 range, select Automatically or Manually.
If you select Manually, enter a
/48range from within thefd20::/20range. If the range is in use, you are prompted to provide a different range.
In the New subnet section, specify the following configuration parameters for a subnet:
- Provide a Name for the subnet.
- Select a Region.
- To create a dual-stack subnet, for IP stack type, select IPv4 and IPv6 (dual-stack).
Enter an IPv4 range. This is the primary IPv4 range for the subnet.
If you select a range that is not an RFC 1918 address, confirm that the range doesn't conflict with an existing configuration. For more information, see IPv4 subnet ranges.
Select an IPv6 access type: External or Internal.
Click Done.
To add more subnets, click Add subnet and repeat the previous steps.
Each subnet in a VPC network can have different stack type and IPv6 access type configurations. You do not need to configure all subnets in a given network as dual-stack subnets.
You can also add more subnets of any stack type to the network after you create the network.
In the Firewall rules section, select zero or more predefined firewall rules in the IPv4 firewall rules and IPv6 firewall rules tabs. The rules address common use cases for connectivity to instances.
If you don't select any predefined rules, you can create your own firewall rules after you create the network.
Each predefined rule name starts with the name of the VPC network that you are creating,
NETWORK. In both the IPv4 firewall rules tab and the IPv6 firewall rules tab, there is an editable predefined ingress firewall rule; the IPv4 rule is namedNETWORK-allow-customand the IPv6 rule is namedNETWORK-allow-ipv6-custom. On the right side of the row that contains the rule, click Edit to select subnets, add additional IP ranges, and specify protocols and ports.The
NETWORK-allow-customandNETWORK-allow-ipv6-customfirewall rule are not automatically updated if you later add additional subnets. If you need firewall rules for the new subnets, you must update the firewall configuration to add the rules.Choose the Dynamic routing mode for the VPC network.
For more information, see dynamic routing mode. You can change the dynamic routing mode later.
Click Create.
gcloud
Use the networks create command.
After you have created the network, you can add subnets
to it.
If you want to configure internal IPv6 ranges on any subnets in this
network, use the --enable-ula-internal-ipv6 flag. This option assigns a
/48 ULA prefix from within the fd20::/20 range used by Google for internal
IPv6 subnet ranges. If you want to select the /48 IPv6 range that is
assigned, use the --internal-ipv6-range flag to specify a range.
You can omit both flags if you want to configure only external IPv6 on subnets in this VPC network.
gcloud compute networks create NETWORK \
--subnet-mode=custom \
[ --enable-ula-internal-ipv6 [ --internal-ipv6-range=ULA_IPV6_RANGE ]] \
--bgp-routing-mode=DYNAMIC_ROUTING_MODE \
--mtu=MTU
Replace the following:
NETWORK: a name for the VPC network.ULA_IPV6_RANGE: a/48prefix from within thefd20::/20range used by Google for internal IPv6 subnet ranges. If you don't use the--internal-ipv6-rangeflag, Google selects a/48prefix for the network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherglobalorregional. The default isregional. For more information, see dynamic routing mode.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.
Terraform
Use the google_compute_network Terraform resource.
If you want to configure internal IPv6 ranges on any subnets in this network,
use the enable_ula_internal_ipv6 argument.
See the following example:
Next, add subnets to your network.
To learn how to apply or remove a Terraform configuration, see Basic Terraform commands.
API
Make a POST request to the
networks.insert method.
After you have created the network, you can add subnets
to it.
If you want to configure internal IPv6 ranges on any subnets in this
network, set enableUlaInternalIpv6 to true. This option assigns a /48
range from within the fd20::/20 range used by Google for internal IPv6
subnet ranges. If you want to select which /48 IPv6 range is assigned,
also use the internalIpv6Range field when you specify a range.
To configure only external IPv6 on subnets in this VPC network, omit both fields.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/networks
{
"autoCreateSubnetworks": false,
"name": "NETWORK",
"mtu": MTU,
"enableUlaInternalIpv6": true,
"internalIpv6Range": "ULA_IPV6_RANGE",
"routingConfig": {
"routingMode": "DYNAMIC_ROUTING_MODE"
}
}
Replace the following:
PROJECT_ID: the ID of the project where the VPC network is created.NETWORK: a name for the VPC network.MTU: the maximum transmission unit (MTU), which is the largest packet size of the network. MTU can be set to any value from1300to8896. The default is1460. Before setting the MTU to a value higher than1460, review Maximum transmission unit.ULA_IPV6_RANGE: a/48prefix from within thefd20::/20range used by Google for internal IPv6 subnet ranges. If you don't provide a value forinternalIpv6Range, Google selects a/48prefix for the network.DYNAMIC_ROUTING_MODE: controls the behavior of Cloud Routers in the network. Can be eitherGLOBALorREGIONAL. The default isREGIONAL. For more information, see dynamic routing mode.
Create a custom mode VPC network with IPv6-only subnets
You can create subnets when you create the network, or you can add them later.
An IPv6-only subnet can have an internal IPv6 range or an external IPv6 range.
Each subnet in a VPC network can have a different configuration; you don't need to configure them all as IPv6-only, for example.
You can't change a dual-stack or IPv4-only subnet to IPv6-only. Conversely, you can't change an IPv6-only subnet to IPv4-only or dual-stack.
By default, the IPv6 addresses for a subnet are provided by Google. If you want to use BYOIP to bring your own IPv6 addresses, see Assign subnet ranges instead.
Console
In the Google Cloud console, go to the VPC networks page.