Customize the subnets in your VPC network that Cloud Router advertises. The subnets that you advertise will be the only ones visible to on-premises clients. Cloud Router won't dynamically advertise new subnets. If you want to advertise new subnets, you must add them to the advertisement.
See Creating Cloud Routers or Establishing BGP sessions to specify advertisements when you create a Cloud Router or configure a BGP session.
To specify advertisements on an existing Cloud Router:
Console
- Go to the Cloud Router page in the Google Cloud Console.
Cloud Router list - Select the Cloud Router to update.
- In the Cloud Router's detail page, select Edit.
- Expand the Advertised routes section.
- For the Routes, select Create custom routes.
- If Advertise all subnets visible to the Cloud Router is selected, clear it.
- Select Add custom route to add an advertised route.
- Configure the route advertisement.
- Source — Select a predefined list of subnets. Cloud Router lists all subnets available to it, which depends on the VPC network's dynamic routing mode.
- IP address range — You can modify the advertised subnet IP range. For example, you can specify a more narrow range so that Cloud Router advertises part of the of the subnet.
- Description — Add a description to help you identify the purpose of this route advertisement.
- After you're done adding routes, select Save.
gcloud
Before you begin, record the IP ranges of the subnets to advertise.
Run the
update
command, using the--set-advertisement-ranges
flag to specify the subnet IP ranges to advertise. To append IP ranges to existing advertisements, use the--add-advertisement-ranges
flag.The following example updates the
my-router
Cloud Router to advertise the10.0.0.0/24
and10.0.10.0/24
subnets. Existing custom advertisements are replaced.gcloud compute routers update my-router \ --advertisement-mode custom \ --set-advertisement-ranges 10.0.0.0/24,10.0.10.0/24
To append IP ranges to an existing advertisement, use the
--add-advertisement-ranges
flag, as shown in the following example:gcloud compute routers update my-router \ --add-advertisement-ranges 10.0.20.0/24
If the advertisement group of your Cloud Router includes all subnets, remove it to prevent Cloud Router from advertising additional subnets. Advertisement groups are Google-defined IP ranges that Cloud Router dynamically advertises. For a list of all advertisements groups, see the
set-advertisement-groups
flag in the Google SDK documentation.Run the describe command to check the Cloud Router's advertisements:
gcloud compute routers describe my-router
If the output contains the
advertisedGroups
field with theALL_SUBNETS
value, remove it. Run the update command with the--remove-advertisement-groups
flag:gcloud compute routers update my-router \ --remove-advertisement-groups all_subnets
API
To specify advertisements on a Cloud Router, use the
routers.patch
method to update the bgp.advertisedIpRanges[]
field. You might also need to update the bgp.advertisedGroups[]
field
if it currently has a value of ALL_SUBNETS
.
The bgp.advertisedGroups[]
and bgp.advertisedIpRanges[]
fields accept arrays of advertised groups and advertised IP address ranges.
When you PATCH
these fields,
you overwrite the existing arrays with the new ones in
your request.
Send a
GET
request to get the current arrays of advertised groups and advertised IP ranges on the router. See Viewing a Cloud Router configuration.Send a
PATCH
request with new arrays of advertised groups and advertised IP address ranges.- Add any subnet IP address ranges that you want on the router to the
bgp.advertisedIpRanges[]
field. - If the value of
advertisedGroups[]
field currently specificesALL_SUBNETS
, remove it by sending an empty array it as shown in the following example. This prevents Cloud Router from advertising additional subnets.
class="devsite-click-to-copy"> PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME { "bgp": { "advertisedGroups": [], "advertisedIpRanges": [ ADVERTISED_IP_RANGES ] } }
Replace the following values:
PROJECT_ID
: the project that contains the Cloud RouterREGION
: the region where the Cloud Router is locatedROUTER_NAME
: the name of the Cloud RouterADVERTISED_IP_RANGES
: the contents of the new array of IP address ranges.See the following example, which contains two subnet IP address ranges:
{ "range": "10.0.0.0/24", "description": "First example range" }, { "range": "10.0.10.0/24", "description": "Second example range" }
- Add any subnet IP address ranges that you want on the router to the
To specify advertisements on an existing BGP session:
Console
- Go to the Cloud Router page in the Google Cloud Console.
Cloud Router list - Select the Cloud Router that contains the BGP session to update.
- In the Cloud Router's detail page, select the BGP session to update.
- In the BGP session details page, select Edit.
- For the Routes, select Create custom routes.
- If Advertise all subnets visible to the Cloud Router is selected, clear it.
- Select Add custom route to add an advertised route.
- Configure the route advertisement.
- Source — Select a predefined list of subnets. Cloud Router lists all subnets available to it, which depends on the VPC network's dynamic routing mode.
- IP address range — You can modify the advertised subnet IP range. For example, you can specify a more narrow range so that Cloud Router advertises part of the of the subnet.
- Description — Add a description to help you identify the purpose of this route advertisement.
- After you're done adding routes, select Save.
gcloud
Before you begin, record the IP ranges of the subnets to advertise.
Run the
update-bgp-peer
command, using the--set-advertisement-ranges
flag to specify the subnet IP ranges to advertise. To append IP ranges to existing advertisements, use the--add-advertisement-ranges
flag.The following example updates the
my-bgp-session
BGP session on themy-router
Cloud Router to advertise the10.0.0.0/24
and10.0.10.0/24
subnets. Existing custom advertisements are replaced.gcloud compute routers update-bgp-peer my-router \ --peer-name my-bgp-session \ --advertisement-mode custom \ --set-advertisement-ranges 10.0.0.0/24,10.0.10.0/24
To append IP ranges to an existing advertisement, use the
--add-advertisement-ranges
flag, as shown in the following example:gcloud compute routers update-bgp-peer my-router \ --peer-name my-bgp-session \ --add-advertisement-ranges 10.0.20.0/24
If the advertisement group of your BGP session includes all subnets, remove it to prevent Cloud Router from advertising additional subnets. Advertisement groups are Google-defined IP ranges that Cloud Router dynamically advertises. For a list of all advertisements groups, see the
set-advertisement-groups
flag in the Google SDK documentation.Run the describe command to check the Cloud Router's advertisements:
gcloud compute routers describe my-router
If the related BGP session contains the
advertisedGroups
field with theALL_SUBNETS
value, remove it. Run the update command with the--remove-advertisement-groups
flag:gcloud compute routers update-bgp-peer my-router \ --peer-name my-bgp-session \ --remove-advertisement-groups all_subnets
API
To specify advertisements for a BGP session, use the
routers.patch
method to update the bgpPeers[]
field.
The bgpPeers[]
field accepts an array of BGP peers. When you PATCH
this field,
you overwrite the existing array of BGP peers with the new array included in
your request.
Send a
GET
request to get the current array of BGP peers for the router. See Viewing a Cloud Router configuration.Send a
PATCH
request with a new array of BGP peers. For each BGP peer for which you want to add advertisements, do the following:- Add any subnet IP address range advertisements that you want to
the
bgpPeers[].advertisedIpRanges[]
field. - If
bgpPeers[].advertisedGroups[]
field currently specifies a valueALL_SUBNETS
, remove it to prevent the BGP session from advertising additional subnets.
PATCH https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION/routers/ROUTER_NAME { "bgpPeers": [ BGP_PEERS ] }
Replace the following values:
PROJECT_ID
: the project that contains the Cloud RouterREGION
: the region where the Cloud Router is locatedROUTER_NAME
: the name of the Cloud RouterBGP_PEERS
: the contents of the new array of BGP peers.See the following example, which 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, "advertisedRoutePriority": 100, "advertiseMode": "CUSTOM", "advertisedGroups": [], "advertisedIpRanges": [ { "range": "10.0.0.0/24", "description": "First example subnet" }, { "range": "10.0.10.0/24", "description": "Second example subnet" } ] }, { "name": "peer-2", "interfaceName": "if-peer-2", "ipAddress": "169.254.20.1", "peerIpAddress": "169.254.20.2", "peerAsn": 64513, "advertisedRoutePriority": 100, "advertiseMode": "CUSTOM", "advertisedGroups": [], "advertisedIpRanges": [ { "range": "10.0.20.0/24", "description": "Third example subnet" } ] }
- Add any subnet IP address range advertisements that you want to
the
What's next
- To view the routes that Cloud Router is advertising, see Viewing Cloud Router status and routes.
- To view the configuration of a Cloud Router and its BGP sessions, see Viewing a Cloud Router configuration.