Create BGP route policies
This guide describes how to create BGP route policies in Cloud Router.
You can create BGP route policies for Cloud Router using any of the following:
- Use your preferred text editor to create a BGP route policy, and then use the gcloud CLI to upload the BGP route policy
The examples on this page create a BGP route policy to set the BGP multiple
exit discriminator (MED) attribute value to 12345
for BGP routes that aren't
included in 192.168.10.0/24
.
Upload a BGP route policy
Create the BGP route policy in your preferred text editor. You can use JSON or YAML formatting to create your BGP route policy. The following example uses a YAML file:
# Modify the MED value for the BGP routes that aren't in the range # 192.168.10.0/24 name: BGP_ROUTE_POLICY_NAME type: ROUTE_POLICY_TYPE terms: - priority: 1 match: expression: > destination != '192.168.10.0/24' actions: - expression: med.set(12345)
Replace the following:
BGP_ROUTE_POLICY_NAME
: a name for the BGP route policy.ROUTE_POLICY_TYPE
: the type of BGP route policy you're creating. The type can be one of the following:ROUTE_POLICY_TYPE_IMPORT
: BGP route policies for inbound routes.ROUTE_POLICY_TYPE_EXPORT
: BGP route policies for outbound routes.
Upload the BGP route policy:
gcloud beta compute routers upload-route-policy ROUTER_NAME \ --region=REGION \ --policy-name=BGP_ROUTE_POLICY_NAME \ --file-name=FILE_NAME \ --file-format=yaml
Replace the following:
ROUTER_NAME
: the name of the Cloud RouterREGION
: the region the Cloud Router is inFILENAME
: the filename that you're uploading
Apply the BGP route policies to BGP peers:
gcloud beta compute routers update-bgp-peer ROUTER_NAME \ --region=REGION \ --peer-name=PEER_NAME \ --import-policies='IMPORT_POLICIES'
Replace the following:
PEER_NAME
: the BGP peer's name to apply the BGP route policy to.IMPORT_POLICIES
: a comma-separated list of import policies. Passing an empty string removes all import policies.