Advertising custom IP ranges

You can update existing Cloud Routers or BGP sessions on a Cloud Router to advertise IP ranges other than your VPC network's subnet IP address ranges. For example, you can advertise external IP addresses, arbitrary internal IP addresses, or internal IP addresses from IP address ranges of subnets in peer VPC networks that are connected by VPC Network Peering.

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


  1. Go to the Cloud Router page in the Google Cloud Console.
    Cloud Router list
  2. Select the Cloud Router to update.
  3. In the Cloud Router's detail page, select Edit.
  4. Expand the Advertised routes section.
  5. For the Routes, select Create custom routes.
  6. Select Advertise all subnets visible to the Cloud Router to continue advertising the subnets available to the Cloud Router. Enabling this option mimics the Cloud Router's default behavior.
  7. Select Add custom route to add an advertised route.
  8. Configure the route advertisement.
    • Source — Select Custom IP range to specify a custom IP range.
    • IP address range — Specify the custom IP range by using CIDR notation.
    • Description — Add a description to help you identify the purpose of this route advertisement.
  9. After you're done adding routes, select Save.

gcloud


Run the update command, using the --set-advertisement-ranges or --add-advertisement-ranges flag to specify the custom IP ranges:

  • To set custom IP ranges, use the --set-advertisement-ranges flag. Any existing custom advertisements are replaced. The following example updates the my-router Cloud Router to advertise all subnets and the custom IP ranges 1.2.3.4 and 6.7.0.0/16:

    gcloud compute routers update my-router \
        --advertisement-mode custom \
        --set-advertisement-groups all_subnets \
        --set-advertisement-ranges 1.2.3.4,6.7.0.0/16
    

    The --set-advertisement-groups flag accepts Google-defined groups that Cloud Router dynamically advertises. You can remove the --set-advertisement-groups flag to exclude subnet advertisements. For a list of all advertisements groups, see the set-advertisement-groups flag in the Google SDK documentation.

  • To append custom IP ranges to an existing advertisement, use the --add-advertisement-ranges flag. Note that this flag requires the Cloud Router's advertisement mode to already be set to custom. The following example, adds the 1.2.3.5 custom IP to the Cloud Router's advertisements:

    gcloud compute routers update my-router \
        --add-advertisement-ranges 1.2.3.5
    

API

To specify advertisements on a Cloud Router, use the routers.patch method to update the bgp.advertisedGroups[] and bgp.advertisedIpRanges[] fields.

The bgp.advertisedGroups[] and bgp.advertisedIpRanges[] fields store 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.

  1. Send a GET request to get the current arrays of advertised groups and advertised IP address ranges on the router. See Viewing a Cloud Router configuration.

  2. Send a PATCH request with new arrays of advertised groups and advertised IP address ranges. Use the arrays from the GET request in the previous step and add any groups or IP address ranges 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 values:

    • 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
    • ADVERTISED_GROUPS: a Google-defined group that Cloud Router dynamically advertises. The only valid value is ALL_SUBNETS, which advertises subnets based on the VPC network's dynamic routing mode (similar to the default advertisements).
    • ADVERTISED_IP_RANGES: the contents of the new array of IP address ranges.

      See the following example, which contains two IP address ranges:

      {
        "range": "1.2.3.4",
        "description": "First example range"
      },
      {
        "range": "6.7.0.0/16",
        "description": "Second example range"
      }
      

To specify advertisements on an existing BGP session:

Console


  1. Go to the Cloud Router page in the Google Cloud Console.
    Cloud Router list
  2. Select the Cloud Router that contains the BGP session to update.
  3. In the Cloud Router's detail page, select the BGP session to update.
  4. In the BGP session details page, select Edit.
  5. For the Routes, select Create custom routes.
  6. Select Advertise all subnets visible to the Cloud Router to continue advertising the subnets available to the Cloud Router. Enabling this option mimics the Cloud Router's default behavior.
  7. Select Add custom route to add an advertised route.
  8. Configure the route advertisement.
    • Source — Select Custom IP range to specify a custom IP range.
    • IP address range — Specify the custom IP range by using CIDR notation.
    • Description — Add a description to help you identify the purpose of this route advertisement.
  9. After you're done adding routes, select Save.

gcloud


Run the update-bgp-peer command, using the --set-advertisement-ranges or --add-advertisement-ranges flag to specify the custom IP ranges.

  • To set custom IP ranges, use the --set-advertisement-ranges flag. Any existing custom advertisements are replaced. The following example updates the my-bgp-session BGP session on the my-router Cloud Router to advertise all subnets and the custom IP ranges 1.2.3.4 and 6.7.0.0/16:

    gcloud compute routers update-bgp-peer my-router \
        --peer-name my-bgp-session \
        --advertisement-mode custom \
        --set-advertisement-groups all_subnets \
        --set-advertisement-ranges 1.2.3.4,6.7.0.0/16
    

    The --set-advertisement-groups flag accepts Google-defined groups that the BGP session dynamically advertises. You can remove the --add-advertisement-groups flag to exclude subnet advertisements. For a list of all advertisements groups, see the set-advertisement-groups flag in the Google SDK documentation.

  • To append custom IP ranges to existing ones, use the --add-advertisement-ranges flag. Note that this flag requires the Cloud Router's advertisement mode to already be set to custom. The following example, adds the 1.2.3.5 custom IP to the Cloud Router's advertisements:

    gcloud compute routers update-bgp-peer my-router \
        --peer-name my-bgp-session \
        --add-advertisement-ranges 1.2.3.5
    

API

To specify advertisements on 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.

  1. Send a GET request to get the current array of BGP peers for the router. See Viewing a Cloud Router configuration.

  2. 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 IP address range advertisements that you want in the bgpPeers[].advertisedIpRanges[] field.
    • Add any group advertisements that you want in the bgpPeers[].advertisedGroups[] field. Valid values are ALL_SUBNETS, ALL_VPC_SUBNETS, and ALL_PEER_VPC_SUBNETS. For more information about these values, see routers.patch in the API documentation.
    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 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.

      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": ["ALL_SUBNETS"],
        "advertisedIpRanges": [
          {
            "range": "1.2.3.4",
            "description": "First example range"
          },
          {
            "range": "6.7.0.0/16",
            "description": "Second 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": "Third example range"
          }
        ]
      }
      

What's next