Use routes (original) (raw)

Skip to main content

This page describes how to create and manage routes for Virtual Private Cloud (VPC) networks in Google Cloud. This page assumes that you are familiar with the different types of Google Cloud routes and their characteristics as described in Routes.

Every new network has two types of system-generated routes: a default route, which you can remove or replace, and one subnet route for each of its subnets. You cannot remove a subnet route unless you delete the corresponding subnet itself.

In addition to the system-generated routes, you can create other custom static routes.

List routes for a VPC network

You can use the Google Cloud CLI or the API to list and view details about the following types of routes:

Neither the gcloud CLI commands nor the API methods show the following types of routes:

To see the complete route view, use the Google Cloud console. To list and describe policy-based routes, see Use policy-based routes.

Console

  1. In the Google Cloud console, go to the Routes page.
    Go to Routes
  2. On the Effective routes tab, do the following:
    • Choose a VPC network.
    • Choose a region.
  3. Click View.
  4. You can filter on properties includingroute type, destination IP range, and next hop type.
  5. Optional: Click the Show suppressed routes toggle to the on position to view routes that are suppressed. To view the reason why a route is suppressed, point to the icon in the Status column.

gcloud

To list and view details for subnet routesand static routes, use the gcloud compute routes commands. These commands don't show other types of routes. To see all routes, use the Google Cloud console.

To list routes, do the following:

gcloud compute routes list
--filter="network=NETWORK_NAME"
--project=PROJECT_ID

To get details for a route, do the following:

gcloud compute routes describe ROUTE_NAME
--format="flattened()"
--project=PROJECT_ID

Replace the following:

API

To list and view details for subnet routesand static routes, use theroutes.list androutes.get methods. These methods don't show other types of routes. To see all routes, use the Google Cloud console.

To list routes, do the following:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes?filter=network="NETWORK_URL

To get details for a route, do the following:

GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes/ROUTE_NAME

Replace the following:

List applicable routes for a VM network interface

You can use the Google Cloud console to view applicable routes for a VM's network interface. This view narrows the list of routes that you can use for egress traffic.

To view applicable routes for a specific network interface of a VM, follow these steps.

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Locate a VM instance in the list. In theMore actions menu at the end of the row, select View network details.
  3. If an instance has multiple network interfaces, in theNetwork interface details section, select the network interface that you want to view.
  4. In the Firewall and routes details section, click the Routes tab to see all the routes that apply to the network interface, sorted by route name.

Add and remove static routes

You can add or remove static routes and policy-based routes that are local to your VPC network. This section describes how to add and delete local static routes. For more information about how to add and remove policy-based routes, seeUse policy-based routes.

Subnet routes are added and deleted automatically when you add or delete a subnet. For more information about how to add and remove subnets, seeWork with subnets.

All routes in a VPC network that are connected by VPC Network Peering must be manipulated in the VPC network that exports those routes. For more information, see Route exchange options.

Before you add a static route

Before you add a static route, consider the following:

Add a static route

Add a static route to a network. For more information about the different types of static route next hops, including which ones support IPv6 destinations, seeNext hops and features.

Console

  1. In the Google Cloud console, go to the Routes page.
    Go to Routes
  2. Click the Route management tab.
  3. Click Create route.
  4. Specify a name and a description for the route.
  5. In the Network list, select an existing network for the route.
  6. In the Route type list, select Static route.
  7. In the IP version list, select the required IP version:
    • To create an IPv4 static route, select IPv4.
    • To create an IPv6 static route, select IPv6.
  8. Specify a destination IP range. The broadest possible destination is0.0.0.0/0 for IPv4 or ::/0 for IPv6.
  9. Specify a priority for the route. The priority can be from 0 (the highest priority) to 65535 (the lowest priority).
  10. To make the route applicable only to select instances with matching network tags, specify those in the Instance tags field. Leave the field blank to make the route applicable to all instances in the network.
  11. Select a next hop for the route:
  1. Click Create.

gcloud

Create a new custom static route with the following gcloud CLI command:

gcloud compute routes create ROUTE_NAME
--network=NETWORK
--destination-range=DESTINATION_RANGE
--priority=PRIORITY
NEXT_HOP_SPECIFICATION

Replace the following:

For more information about the gcloud CLI syntax, see theSDK documentation.

API

Create a new custom static route.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes { "name": "ROUTE_NAME", "network": "NETWORK_NAME", "destRange": "DESTINATION_RANGE", "priority": PRIORITY, "NEXT_HOP_SPECIFICATION" }

Replace the following:

To make the custom static route apply to only select VMs by network tag, add the tags field and specify one or more network tags. For more information about how network tags and custom static routes work together, see Applicable routes in the Routes overview. You can use tags with any custom static route.

For more information, refer to theroutes.insert method.

Terraform

You can create a static route by using aTerraform module.

This static route creates a default route to the internet.

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

Go

Java

Python

Add an IPv4 default route

The IPv4 default static route (0.0.0.0/0) with the next-hop-gateway set todefault-internet-gateway is automatically configured for each VPC network. Use these steps to re-create this route if necessary.

Console

  1. In the Google Cloud console, go to the Routes page.
    Go to Routes
  2. Click the Route management tab.
  3. Click Create route.
  4. Specify a name and a description for the route.
  5. Select an existing network for the route.
  6. For Destination IP range, enter 0.0.0.0/0.
  7. Specify a priority for the route. The priority can be from 0 (the highest priority) to 65535 (the lowest priority).
  8. For Next hop, select Default internet gateway.
  9. Click Create.

gcloud

Recreate the IPv4 default route for a network.

gcloud compute routes create ROUTE_NAME
--destination-range=0.0.0.0/0
--network=NETWORK
--next-hop-gateway=default-internet-gateway

Replace the following:

API

Recreate the IPv4 default route for a network.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes { "destRange": "0.0.0.0/0", "name": "ROUTE_NAME", "network": "NETWORK_NAME", "nextHopGateway": "projects/PROJECT_ID/global/gateways/default-internet-gateway" }

Replace the following:

Add an IPv6 default route

The IPv6 default static route (::/0) with the next-hop-gateway set to default-internet-gateway is automatically configured for the VPC network when you create a subnet with the IPv6 access type set to external. You can delete the route to block all IPv6 traffic from VMs to the internet. You can also recreate the route if needed.

Console

  1. In the Google Cloud console, go to the Routes page.
    Go to Routes
  2. Click the Route management tab.
  3. Click Create route.
  4. Specify a name and a description for the route.
  5. Select an existing network for the route.
  6. For Destination IP range, enter ::/0.
  7. Specify a priority for the route. The priority can be from 0 (the highest priority) to 65535 (the lowest priority).
  8. For Next hop, select Default internet gateway.
  9. Click Create.

gcloud

Recreate the IPv6 default route for a network.

gcloud compute routes create ROUTE_NAME
--destination-range=::/0
--network=NETWORK
--next-hop-gateway=default-internet-gateway

Replace the following:

API

Recreate the IPv6 default route for a network.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes { "destRange": "::/0", "name": "ROUTE_NAME", "network": "NETWORK_NAME", "nextHopGateway": "projects/PROJECT_ID/global/gateways/default-internet-gateway" }

Replace the following:

Modify a static route

You cannot edit or update a static route after you create it. To modify a static route, you must delete it and create a replacement.

Delete a static route

To delete a route, do the following.

Console

  1. In the Google Cloud console, go to the Routes page.
    Go to Routes
  2. Click the Route management tab.
  3. Select the checkbox next to the rule that you want to delete.
  4. Click Delete.
  5. Click Delete again to confirm.

gcloud

Delete a custom static route by using the following gcloud CLI command:

gcloud compute routes delete ROUTE_NAME

Replace ROUTE_NAME with the name of the route that you want to delete.

API

Delete a custom static route to remove it from your VPC network by using theroutes.delete method:

DELETE https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/routes/ROUTE_NAME

Replace the following:

Go

Java

Python

Propagation of route changes

When you add or delete a static route, the route propagates to all regions and VM instances in your VPC network. A route operation status of PENDING or RUNNING indicates that the route change is queued.

After queueing, the route operation status changes to DONE. It might take an additional 30 seconds before all VM instances in your VPC network and VPC Network Peering networks use a new route or stop using an old route.

If you add or remove several static routes simultaneously, the changes can be applied in any order. There is no guarantee that the order in which you submit route changes is the order in which they are processed. Different instances might become aware of the changes at different times.

If you need to make route changes that depend on each other, you must make those changes sequentially by performing subsequent changes only after the previous change's status is DONE and an additional 30 seconds has elapsed.

Enable IP forwarding for instances

By default, IP forwarding is disabled, and Google Cloud performs strict source address checking. Subject to the effective egress firewall configuration, a VM can emit packets with the following sources:

To use a VM as a next hop for a route, the VM needs to forward packets whose sources don't match one of the IP addresses or ranges in the preceding list. To forward packets with arbitrary source addresses, you must enable IP forwarding:

To enable IP forwarding when you create a VM, complete the following steps.

Console

  1. In the Google Cloud console, go to the VM instances page.
    Go to VM instances
  2. Click Create instance.
  3. In the Advanced options section, expand Networking, disks, security, management, sole-tenancy.
  4. Expand the Networking section.
  5. In the IP forwarding section, select the Enable checkbox.

gcloud

When creating an instance, add the --can-ip-forward flag to your command:

gcloud compute instances create ... --can-ip-forward

API

When creating an instance, use the canIpForward field to enable IP forwarding:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances { "canIpForward": true, ...other fields }

Replace the following:

For more information, see theinstances.insert method.

Terraform

You can use the Terraform resourceto create a VM instance with IP forwarding enabled.

In this example, the Terraform arguments have assigned values that you can change.

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

After you enable IP forwarding, continue with the VM creation process.

To enable IP forwarding on an existing VM, update the canIpForwardinstance property.

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.