Disabling or terminating BGP sessions

You can disable a BGP session temporarily or terminate it entirely. Some common reasons for disabling a session are changing router configuration when migrating to a different BGP peer or performing maintenance on a BGP peer.

Before you begin

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

  1. Install or update to the latest version of the gcloud command-line tool.
  2. Set a default region and zone.

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

Disable a BGP session

You can disable a BGP session by using the Google Cloud Console, the update-bgp-peer command, or the API. BGP sessions are enabled by default.

If disabled, any active session with the BGP peer is terminated, and all associated routing information is removed.

To disable a BGP session, follow these steps.

Console

  1. In the Google Cloud Console, go to the Cloud Routers page.

    Go to Cloud Routers

  2. Select the router whose BGP session you want to disable.

  3. On the Router details page, click Edit.

  4. Under BGP peer, select Disabled.

  5. Click Update.

gcloud

Run the update-bgp-peer command:

  gcloud compute routers update-bgp-peer ROUTER_NAME \
      --project=PROJECT_ID \
      --peer-name=PEER_NAME \
      --region=REGION \
      --no-enabled

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • PROJECT_ID: the project that contains the Cloud Router
  • PEER_NAME: the name of your BGP peer
  • REGION: the region where the Cloud Router is located

API

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.

  1. Send a GET request to get the current array of BGP peers for the router. For details, see Viewing BGP session configuration.

  2. Send a PATCH request with a new array of BGP peers. For each BGP peer for which you want to disable the BGP session, set bgpPeers[].enable to FALSE.

    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 the Cloud Router
    • REGION: the region where the Cloud Router is located
    • ROUTER_NAME: the name of the Cloud Router
    • BGP_PEERS: the contents of the new array of BGP peers

    The following example disables the session for the first BGP peer:

        {
          "name": "peer-1",
          "interfaceName": "if-peer-1",
          "ipAddress": "169.254.10.1",
          "peerIpAddress": "169.254.10.2",
          "peerAsn": 64512,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT",
          "advertisedGroups": [],
          "advertisedIpRanges": [],
          "enable": FALSE
        },
        {
          "name": "peer-2",
          "interfaceName": "if-peer-2",
          "ipAddress": "169.254.20.1",
          "peerIpAddress": "169.254.20.2",
          "peerAsn": 64513,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT",
          "advertisedGroups": [],
          "advertisedIpRanges": []
        }
    

Enable a BGP session

You can enable a BGP session by using the Google Cloud Console, the update-bgp-peer command, or the API. BGP sessions are enabled by default.

If enabled, the peer connection can be established with routing information.

To enable a BGP session, follow these steps.

Console

  1. In the Google Cloud Console, go to the Cloud Routers page.

    Go to Cloud Routers

  2. Select the router whose BGP session you want to enable.

  3. On the Router details page, click Edit.

  4. Under BGP peer, select Enabled.

  5. Click Update.

gcloud

Run the update-bgp-peer command:

  gcloud compute routers update-bgp-peer ROUTER_NAME \
      --project=PROJECT_ID \
      --peer-name=PEER_NAME \
      --region=REGION \
      --enabled

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • PROJECT_ID: the project that contains the Cloud Router
  • PEER_NAME: the name of your BGP peer
  • REGION: the region where the Cloud Router is located

API

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.

  1. Send a GET request to get the current array of BGP peers for the router. For details, see Viewing Cloud Router details.

  2. Send a PATCH request with a new array of BGP peers. For each BGP peer for which you want to enable the BGP session, set bgpPeers[].enable to TRUE.

    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 the Cloud Router
    • REGION: the region where the Cloud Router is located
    • ROUTER_NAME: the name of the Cloud Router
    • BGP_PEERS: the contents of the new array of BGP peers

    The following example enables the session for the first BGP peer:

        {
          "name": "peer-1",
          "interfaceName": "if-peer-1",
          "ipAddress": "169.254.10.1",
          "peerIpAddress": "169.254.10.2",
          "peerAsn": 64512,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT",
          "advertisedGroups": [],
          "advertisedIpRanges": [],
          "enable": TRUE
        },
        {
          "name": "peer-2",
          "interfaceName": "if-peer-2",
          "ipAddress": "169.254.20.1",
          "peerIpAddress": "169.254.20.2",
          "peerAsn": 64513,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT",
          "advertisedGroups": [],
          "advertisedIpRanges": []
        }
    

Terminate a BGP session

If you delete the Cloud VPN tunnel or VLAN attachment associated with a BGP session, the session is automatically terminated.

You can terminate BGP sessions manually by using the Google Cloud Console, the remove-bgp-peer command, or the API. If you terminate the BGP session, the VPN tunnel or VLAN attachment remains, but the Cloud Router doesn't advertise routes over them.

To terminate a BGP session, follow these steps.

Console

  1. In the Google Cloud Console, go to the Cloud Routers page.

    Go to Cloud Routers

  2. Select the router whose BGP session you want to remove.

  3. Under BGP sessions, select the BGP session that you want to remove.

  4. At the top of the page, click Delete and confirm the deletion.

gcloud

Run the remove-bgp-peer command:

gcloud compute routers remove-bgp-peer ROUTER_NAME \
    --project=PROJECT_ID \
    --peer-name=PEER_NAME \
    --region=REGION \

Replace the following:

  • ROUTER_NAME: the name of your Cloud Router
  • PROJECT_ID: the project that contains the Cloud Router
  • PEER_NAME: the name of your BGP peer
  • REGION: the region where the Cloud Router is located

API

To remove BGP peers from a Cloud Router, 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.

  1. Send a GET request to get the current array of BGP peers for the router. For details, see Viewing Cloud Router details.

  2. Send a PATCH request with a new array of BGP peers. Use the array from the GET request in the previous step, and remove any BGP peers that you do not want on the router.

    You can send an empty array to remove all BGP peers.

    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 the Cloud Router
    • REGION: the region where the Cloud Router is 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:

        {
          "name": "peer-1",
          "interfaceName": "if-peer-1",
          "ipAddress": "169.254.10.1",
          "peerIpAddress": "169.254.10.2",
          "peerAsn": 64512,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT"
        },
        {
          "name": "peer-2",
          "interfaceName": "if-peer-2",
          "ipAddress": "169.254.20.1",
          "peerIpAddress": "169.254.20.2",
          "peerAsn": 64513,
          "advertisedRoutePriority": 100,
          "advertiseMode": "DEFAULT"
        }
    

What's next

  • To view the configuration of a Cloud Router, its BGP sessions, and the routes that Cloud Router is advertising, see Viewing Cloud Router details.
  • To troubleshoot issues when using Cloud Router, see Troubleshooting.