Apply BGP route policies

This guide describes how to apply BGP route policies in Cloud Router.

Add a BGP route policy to a BGP peer

Adding a BGP route policy to a BGP peer replaces all existing BGP policies for the peer. For example, --import-policies= removes all existing import policies for the listed BGP peer, and --import-policies=my-import-policy1,my-import-policy2 replaces the existing import policy chain defined for the peer.

To add a BGP route policy to a BGP peer, run the following command:

gcloud beta compute routers add-bgp-peer ROUTER_NAME \
    --peer-name=PEER_NAME \
    --import-policies=IMPORT_POLICIES \
    --export-policies=EXPORT_POLICIES

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • PEER_NAME: the name of the BGP peer that the policies apply to
  • IMPORT_POLICIES: a comma-separated list of import policies to apply to the named peer
  • EXPORT_POLICIES: a comma-separated list of export policies to apply to the named peer

The command fails if any of the following are true:

  • --peer-name= doesn't list an existing peer
  • --import-policy= doesn't list an existing import policy
  • --export-policy= doesn't list an existing export policy

Update a BGP route policy to a BGP peer

Updating a BGP route policy to a BGP peer replaces all existing BGP policies for the peer. For example, --import-policies= removes all existing import policies for the listed BGP peer, and --import-policies=my-import-policy1,my-import-policy2 replaces the existing import policy chain defined for the peer.

To update a BGP route policy to a BGP peer, run the following command:

gcloud beta compute routers update-bgp-peer ROUTER_NAME \
    --peer-name=PEER_NAME \
    --import-policies=IMPORT_POLICIES \
    --export-policies=EXPORT_POLICIES

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • PEER_NAME: the name of the BGP peer that the policies apply to
  • IMPORT_POLICIES: a comma-separated list of import policies to apply to the named peer
  • EXPORT_POLICIES: a comma-separated list of export policies to apply to the named peer

The command fails if any of the following are true:

  • --peer-name= doesn't list an existing peer
  • --import-policy= doesn't list an existing import policy
  • --export-policy= doesn't list an existing export policy

Download a BGP route policy

To download a BGP route policy to your computer, run the following command:

gcloud beta compute routers download-route-policy ROUTER_NAME \
    --policy-name=BGP_ROUTE_POLICY_NAME \
    --file-name=FILE_NAME

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • BGP_ROUTE_POLICY_NAME: the name of the BGP route policy that you want to export
  • FILE_NAME: the name of the file to download the route policy to

The output defaults to a YAML file. To export a JSON file, run the following command:

gcloud beta compute routers download-route-policy ROUTER_NAME \
    --policy-name=BGP_ROUTE_POLICY_NAME \
    --file-name=FILE_NAME \
    --format=json

Display a BGP route policy

To display a BGP route policy, run the following command:

gcloud beta compute routers get-route-policy ROUTER_NAME \
    --policy-name=BGP_ROUTE_POLICY_NAME

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • BGP_ROUTE_POLICY_NAME: the name of the BGP route policy that you want to export

The output defaults to a YAML file. To export a JSON file, run the following command:

gcloud beta compute routers get-route-policy ROUTER_NAME \
    --policy-name=BGP_ROUTE_POLICY_NAME \
    --format=json

What's next