Advertise custom address ranges

Use custom advertisement mode in a Cloud Router or a Border Gateway Protocol(BGP) session on a Cloud Router to advertise IP address ranges otherthan your Virtual Private Cloud (VPC) network's subnet IP address ranges.For example, you can advertise external IP address ranges, arbitrary internal IPaddress ranges, or internal IP addresses from IP address ranges fromother VPC networks that are connected to your VPCnetwork. Your VPC network might be connected throughVPC Network Peering or VPC spokes in Network Connectivity Center.

When a Cloud Router is configured to use default advertisement mode,it only advertises routes for subnets that are part of the same VPCnetwork as the Cloud Router. In this mode, Cloud Routerexcludes any static routes and routes that are learned dynamically from otherVPC networks, such as routes learned by VPC Network Peeringor by VPC spokes in NCC.

Caution: You can specify custom advertised routes on a Cloud Routerand on a BGP session. Custom advertised routes on the Cloud Routerapply to all of its BGP sessions. However, if you specify any custom advertised route on a BGP session, all of the Cloud Router's advertised routesare ignored and overridden by the BGP session's custom advertised route.

To specify custom advertised routes when you create a Cloud Router or configurea BGP session, seeCreate Cloud Routers orEstablish BGP sessions.

Before you begin

gcloud

If you want to use the command-line examples in this guide, do the following:

  1. Install or update to the latest version of theGoogle Cloud CLI.
  2. Set adefault region andzone.

API

If you want to use the API examples in this guide, set upAPI access.

Specify custom advertised routes on a Cloud Router

To specify custom advertised routes on an existing Cloud Router, follow thesesteps.

Console

  1. In the Google Cloud console, go to theCloud Routers page.

    Go to Cloud Routers

  2. Select the Cloud Router to update.

  3. On theRouter details page, clickEdit.

  4. In theAdvertised routes section, forRoutes, selectCreate custom routes.

  5. Select theAdvertise all subnets visible to the Cloud Router checkboxto continue advertising the subnets available to theCloud Router. Enabling this option mimics thebehavior of Cloud Router indefault advertisement mode.

  6. SelectAdd custom route to add an advertised route.

  7. Configure the custom advertised routes:

    • Source: SelectCustom IP range.

    • IP address range: Use CIDR notation to specify the custom IPrange.

      You can specify both IPv4 and IPv6 custom IP ranges.However, IPv6 custom ranges are advertised only in BGP sessionswhere IPv6 is enabled.

      If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6.For information about the maximum number of custom learned routesthat you can have, seeLimits.

    • Description: Add a description to help you identify thepurpose of this custom advertised route, and then clickDone.

  8. After you finish adding custom advertised routes, clickSave.

gcloud

Run theupdate command. To specify the custom IP ranges, use the--set-advertisement-ranges flag or the--add-advertisement-ranges flag.

  1. Use the--set-advertisement-ranges flag; any existing customadvertisements are replaced:

    gcloud compute routers updateROUTER_NAME \   --project=PROJECT_ID \   --advertisement-mode custom \   --set-advertisement-groups=ADVERTISED_GROUPS \   --set-advertisement-ranges=ADVERTISED_IP_RANGES

    Replace the following:

    • ROUTER_NAME: the name of the Cloud Router
    • PROJECT_ID: the project that contains theCloud Router
    • ADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertises

      The only valid value isall_subnets, which advertises subnets basedon the VPC network's dynamic routing mode (similar todefault advertisement mode).

    • ADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges

      You can specify both IPv4 and IPv6 custom IP ranges. However, IPv6custom ranges are advertised only in BGP sessions where IPv6 isenabled.

      If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6.For information about the maximum number of custom learned routes thatyou can have, seeLimits.

    The following example updates themy-router Cloud Routerto advertise all subnets and the custom IP ranges192.0.2.0/24 and198.51.100.0/24:

    gcloud compute routers update my-router \   --advertisement-mode custom \   --set-advertisement-groups=all_subnets \   --set-advertisement-ranges='192.0.2.0/24,198.51.100.0/24'

    The following example updates themy-router Cloud Routerto advertise all subnets and the default IPv6 range:

    gcloud compute routers update my-router \   --advertisement-mode custom \   --set-advertisement-groups=all_subnets \   --set-advertisement-ranges='2001:db8:abcd:12::/64'

    Cloud Router advertises IPv6 ranges only in BGP sessions thatare enabled for IPv6.

    The--set-advertisement-groups flag accepts Google-defined groups that theCloud Router dynamically advertises. You can remove the--set-advertisement-groups flag to exclude subnet advertisements. Fora list of all advertisement groups, see theset-advertisement-groupsflag in the Google SDK documentation.

  2. Use the--add-advertisement-ranges flag, which requires theCloud Router's advertisement mode to already be set tocustom:

    gcloud compute routers updateROUTER_NAME \   --add-advertisement-ranges=ADVERTISED_IP_RANGES

    Replace the following:

    • ROUTER_NAME: the name of the Cloud Router
    • ADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges

    The following example adds the203.0.113.1 custom IP address to theCloud Router's advertisements:

    gcloud compute routers update my-router \   --add-advertisement-ranges='203.0.113.1'

    The following example adds the2001:db8:abcd:12::/64 custom IPv6 rangeto the Cloud Router's advertisements:

    gcloud compute routers update my-router \   --add-advertisement-ranges='2001:db8:abcd:12::/64'

    Cloud Router advertises IPv6 ranges only in BGP sessionsthat are enabled for IPv6.

API

Use therouters.patchmethod to update thebgp.advertisedGroups[] andbgp.advertisedIpRanges[]fields.

Thebgp.advertisedGroups[] andbgp.advertisedIpRanges[]fields store arrays of advertised groups and advertised IP address ranges.When youPATCH these fields, you overwrite the existing arrays with thenew ones in your request.

  1. Send aGET request to get the current arrays of advertised groupsand advertised IP address ranges on the router.For details, seeView BGP session configuration.

  2. Send aPATCH request with new arrays of advertised groups andadvertised IP address ranges. Use the arrays fromtheGET request in the previous step, and add any groups or IP addressranges that you want on the router.

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME{  "bgp": {    "advertisedGroups": [    "ADVERTISED_GROUPS"   ],    "advertisedIpRanges": [ADVERTISED_IP_RANGES   ] }}

    Replace the following:

    • PROJECT_ID: the project that contains theCloud Router
    • REGION: the region where the Cloud Routeris located
    • ROUTER_NAME: the name of the Cloud Router
    • ADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertises

    The only valid value isALL_SUBNETS, which advertises subnets basedon the VPC network's dynamic routing mode (similar tothe default advertisements).

    • ADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges

    You can specify both IPv4 and IPv6 custom IP ranges. However, IPv6custom ranges are advertised only in BGP sessions where IPv6 is enabled.

    If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6.For information about the maximum number of custom learned routes thatyou can have, seeLimits.

    The following example contains two IPv4 address ranges and one IPv6address range:

        {      "range": "192.0.2.0/24",      "description": "First example range"    },    {      "range": "198.51.100.0/24",      "description": "Second example range"    },    {      "range": "2001:db8:abcd:12::/64",      "description: "Third example range"    }

Specify custom advertised routes for a BGP session

To specify custom advertised routes for an existing BGP session, follow these steps.

Console

  1. In the Google Cloud console, go to theCloud Routers page.

    Go to Cloud Routers

  2. Select the Cloud Router that contains the BGP session toupdate.

  3. On theRouter details page, select the BGP session to update.

  4. On theBGP session details page, clickEdit.

  5. ForRoutes, selectCreate custom routes.

  6. Select theAdvertise all subnets visible to the Cloud Router checkboxto continue advertising the subnets available to theCloud Router. Enabling this option mimics theCloud Router's default behavior.

  7. SelectAdd custom route to add an advertised route.

  8. Configure the route advertisement:

    • Source: SelectCustom IP range.

    • IP address range: Use CIDR notation to specify the custom IPrange. You can specify both IPv4 and IPv6 custom IP ranges. However,IPv6 custom ranges are advertised only in BGP sessions where IPv6 isenabled.

      If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6. Forinformation about the maximum number of custom learned routes that youcan have, seeLimits.

    • Description: Add a description to help you identify thepurpose of this route advertisement, and then clickDone.

  9. After you finish adding custom routes, clickSave.

gcloud

Run theupdate-bgp-peer command. To specify the custom IP ranges, use the--set-advertisement-ranges flag or the--add-advertisement-ranges flag.

  1. Use the--set-advertisement-ranges flag; any existing customadvertisements are replaced:

    gcloud compute routers update-bgp-peerROUTER_NAME \    --peer-name=PEER_NAME \    --advertisement-mode custom \    --set-advertisement-groups=ADVERTISED_GROUPS \    --set-advertisement-ranges=ADVERTISED_IP_RANGES

    Replace the following:

    • ROUTER_NAME: the name of the Cloud Router
    • PEER_NAME: the name of your BGP peer
    • Optionally, add the--enable-ipv6 flag if you are adding custom IPv6ranges.
    • ADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertises

      The only valid value isall_subnets, which advertises subnets basedon the VPC network's dynamic routing mode (similar tothe default advertisements).

    • ADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges

      You can specify both IPv4 and IPv6 custom IP ranges. However, IPv6custom ranges are advertised only in BGP sessions where IPv6 isenabled.

      If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6.For information about the maximum number of custom learned routesthat you can have, seeLimits.

    The following example updates themy-bgp-session BGP session on themy-router Cloud Router to advertise all subnets and thecustom IP ranges192.0.2.1,198.51.100.0/24, and2001:db8:abcd:12::/64.

    gcloud compute routers update-bgp-peer my-router \    --peer-name my-bgp-session \    --enable-ipv6 \    --advertisement-mode custom \    --set-advertisement-groups=all_subnets \    --set-advertisement-ranges='192.0.2.1,198.51.100.0/24,2001:db8:abcd:12::/64'

    The--set-advertisement-groups flag accepts Google-defined groups thatthe BGP session dynamically advertises. You can remove the--add-advertisement-groups flag to exclude subnet advertisements. Fora list of all advertisement groups, see theset-advertisement-groupsflag in the Google SDK documentation.

  2. Use the--add-advertisement-ranges flag, which requires theCloud Router's advertisement mode to already be set tocustom:

    gcloud compute routers update-bgp-peerROUTER_NAME \    --peer-name=PEER_NAME \    --add-advertisement-ranges=ADVERTISED_IP_RANGES

    Replace the following:

    • ROUTER_NAME: the name of the Cloud Router
    • PEER_NAME: the name of your BGP peer
    • ADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges

      You can specify both IPv4 and IPv6 custom IP ranges. However, IPv6custom ranges are advertised only in BGP sessions where IPv6 isenabled.

      If you provide an IP address prefix without a subnet mask, it isinterpreted as a/32 subnet mask for IPv4 and a/128 for IPv6.For information about the maximum number of custom learned routesthat you can have, seeLimits.

    The following example adds the198.51.100.1 custom IP address to theCloud Router's advertisements:

    gcloud compute routers update-bgp-peer my-router \    --peer-name my-bgp-session \    --add-advertisement-ranges='198.51.100.1'

    The following example adds the2001:db8:abcd:12::/64 custom IPv6 address to the Cloud Router's advertisements:

    gcloud compute routers update-bgp-peer my-router \    --peer-name my-bgp-session \    --enable-ipv6 \    --add-advertisement-ranges='2001:db8:abcd:12::/64'

API

Use therouters.patchmethod to update thebgpPeers[] field.

ThebgpPeers[] field accepts an array of BGP peers. When youPATCH thisfield, you overwrite the existing array of BGP peers with the new arrayincluded in your request.

  1. Send aGET request to get the current array of BGP peers for the router.For details, seeView BGP session configuration.

  2. Send aPATCH request with a new array of BGP peers. For each BGP peer forwhich you want to add advertisements, do the following:

    • Add any IP address range advertisements that you want inthebgpPeers[].advertisedIpRanges[] field.
    • Add any group advertisements that you want in thebgpPeers[].advertisedGroups[] field.

      The only valid value isALL_SUBNETS, which advertises subnets basedon the VPC network's dynamic routing mode (similar todefault advertisement mode).

      For more information about these values, seerouters.patchin the API documentation.

    PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME{  "bgpPeers": [BGP_PEERS  ]}

    Replace the following:

    • PROJECT_ID: the project that contains theCloud Router
    • REGION: the region where the Cloud Routeris located
    • ROUTER_NAME: the name of the Cloud Router
    • BGP_PEERS: the contents of the new array of BGP peers

    The following example contains two BGP peers with custom advertisements:

        {      "name": "peer-1",      "interfaceName": "if-peer-1",      "ipAddress": "169.254.10.1",      "peerIpAddress": "169.254.10.2",      "peerAsn": 64512,      "enableIpv6": true,      "advertisedRoutePriority": 100,      "advertiseMode": "CUSTOM","advertisedGroups": ["ALL_SUBNETS"],      "advertisedIpRanges": [        {          "range": "1.2.3.4",          "description": "First example range"        },        {          "range": "6.7.0.0/16",          "description": "Second example range"        },        {          "range": "2001:db8:abcd:12::/64",          "description: "Third example range"        }      ]    },    {      "name": "peer-2",      "interfaceName": "if-peer-2",      "ipAddress": "169.254.20.1",      "peerIpAddress": "169.254.20.2",      "peerAsn": 64513,      "advertisedRoutePriority": 100,      "advertiseMode": "CUSTOM","advertisedIpRanges": [        {          "range": "192.168.10.0/24",          "description": "Fourth example range"        }      ]    }

What's next

  • To view the configuration of a Cloud Router, its BGP sessions, andthe routes that Cloud Router is advertising, seeView Cloud Router details.

  • To troubleshoot issues with custom advertised routes, seeTroubleshooting.

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

Last updated 2026-02-19 UTC.