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:
- Install or update to the latest version of theGoogle Cloud CLI.
- 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
In the Google Cloud console, go to theCloud Routers page.
Select the Cloud Router to update.
On theRouter details page, clickEdit.
In theAdvertised routes section, forRoutes, selectCreate custom routes.
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.
SelectAdd custom route to add an advertised route.
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
/32subnet mask for IPv4 and a/128for 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.
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.
Use the
--set-advertisement-rangesflag; 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 RouterPROJECT_ID: the project that contains theCloud RouterADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertisesThe only valid value is
all_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 rangesYou 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
/32subnet mask for IPv4 and a/128for IPv6.For information about the maximum number of custom learned routes thatyou can have, seeLimits.
The following example updates the
my-routerCloud Routerto advertise all subnets and the custom IP ranges192.0.2.0/24and198.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 the
my-routerCloud 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-groupsflag accepts Google-defined groups that theCloud Router dynamically advertises. You can remove the--set-advertisement-groupsflag to exclude subnet advertisements. Fora list of all advertisement groups, see theset-advertisement-groupsflag in the Google SDK documentation.Use the
--add-advertisement-rangesflag, 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 RouterADVERTISED_IP_RANGES: the contents of the new arrayof IP address ranges
The following example adds the
203.0.113.1custom IP address to theCloud Router's advertisements:gcloud compute routers update my-router \ --add-advertisement-ranges='203.0.113.1'
The following example adds the
2001:db8:abcd:12::/64custom 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.
Send a
GETrequest to get the current arrays of advertised groupsand advertised IP address ranges on the router.For details, seeView BGP session configuration.Send a
PATCHrequest with new arrays of advertised groups andadvertised IP address ranges. Use the arrays fromtheGETrequest 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 RouterREGION: the region where the Cloud Routeris locatedROUTER_NAME: the name of the Cloud RouterADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertises
The only valid value is
ALL_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
/32subnet mask for IPv4 and a/128for 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
In the Google Cloud console, go to theCloud Routers page.
Select the Cloud Router that contains the BGP session toupdate.
On theRouter details page, select the BGP session to update.
On theBGP session details page, clickEdit.
ForRoutes, selectCreate custom routes.
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.
SelectAdd custom route to add an advertised route.
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
/32subnet mask for IPv4 and a/128for 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.
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.
Use the
--set-advertisement-rangesflag; 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 RouterPEER_NAME: the name of your BGP peer- Optionally, add the
--enable-ipv6flag if you are adding custom IPv6ranges. ADVERTISED_GROUPS: a Google-defined group thatCloud Router dynamically advertisesThe only valid value is
all_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 rangesYou 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
/32subnet mask for IPv4 and a/128for IPv6.For information about the maximum number of custom learned routesthat you can have, seeLimits.
The following example updates the
my-bgp-sessionBGP session on themy-routerCloud 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-groupsflag accepts Google-defined groups thatthe BGP session dynamically advertises. You can remove the--add-advertisement-groupsflag to exclude subnet advertisements. Fora list of all advertisement groups, see theset-advertisement-groupsflag in the Google SDK documentation.Use the
--add-advertisement-rangesflag, 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 RouterPEER_NAME: the name of your BGP peerADVERTISED_IP_RANGES: the contents of the new arrayof IP address rangesYou 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
/32subnet mask for IPv4 and a/128for IPv6.For information about the maximum number of custom learned routesthat you can have, seeLimits.
The following example adds the
198.51.100.1custom 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 the
2001:db8:abcd:12::/64custom 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.
Send a
GETrequest to get the current array of BGP peers for the router.For details, seeView BGP session configuration.Send a
PATCHrequest 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 inthe
bgpPeers[].advertisedIpRanges[]field. Add any group advertisements that you want in the
bgpPeers[].advertisedGroups[]field.The only valid value is
ALL_SUBNETS, which advertises subnets basedon the VPC network's dynamic routing mode (similar todefault advertisement mode).For more information about these values, see
routers.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 RouterREGION: the region where the Cloud Routeris locatedROUTER_NAME: the name of the Cloud RouterBGP_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" } ] }- Add any IP address range advertisements that you want inthe
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.