Creating a Classic VPN using dynamic routing

This page describes how to create a Classic VPN gateway and one tunnel using dynamic routing, which uses the Border Gateway routing Protocol (BGP).

With dynamic routing, you do not specify local or remote traffic selectors; instead, you use a Cloud Router. Route information is exchanged dynamically.

Before you begin

Setting up the following items in GCP makes it easier to configure Cloud VPN:

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Select or create a GCP project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project. Learn how to confirm billing is enabled for your project.

  4. Install and initialize the Cloud SDK.
  1. If you are using gcloud commands, set your project ID with the following command. The gcloud instructions on this page assume that you have set your project ID before issuing commands.
  gcloud config set project project-id

You can also view a project ID that has already been set:

  gcloud config list --format='text(core.project)'

Creating a custom Virtual Private Cloud network and subnet

Before creating an Classic VPN gateway and tunnel, you must create a Virtual Private Cloud network and at least one subnet in the region where the Classic VPN gateway will reside.

Creating a gateway and tunnel

The VPN setup wizard is the only console option for creating a Classic VPN gateway. The wizard includes all required configuration steps for creating a Classic VPN gateway, tunnels, BGP sessions, and an external VPN gateway resource. However, you can complete certain steps later. For example, configuring BGP sessions.

The Create a VPN button only supports creating HA VPN gateways.

Console

Configure the Gateway

  1. Go to the VPN page in the Google Cloud Platform Console.
    Go to the VPN page
  2. Click VPN setup wizard.
  3. On the Create a VPN page, specify Classic VPN.
  4. Click Continue.
  5. On the Create a VPN connection page, specify the following gateway settings:
    • Name — The name of the VPN gateway. The name cannot be changed later.
    • Description — Optionally, add a description.
    • Network — Specify an existing VPC network in which to create the VPN gateway and tunnel.
    • Region — Cloud VPN gateways and tunnels are regional objects. Choose a GCP region where the gateway will be located. Instances and other resources in different regions can use the tunnel for egress traffic subject to the order of routes. For best performance, locate the gateway and tunnel in the same region as relevant GCP resources.
    • IP address — Create or choose an existing regional external IP address.

Configure Tunnels

  1. Specify the following in the Tunnels section for the new tunnel item:
    • Name — The name of the VPN tunnel. The name cannot be changed later.
    • Description — Optionally, type a description.
    • Remote peer IP address — Specify the public IP address of the peer VPN gateway.
    • IKE version — Choose the appropriate IKE version supported by the peer VPN gateway. IKEv2 is preferred if it's supported by the peer device.
    • Shared secret — Provide a pre-shared key used for authentication. The shared secret for the Cloud VPN tunnel must match the one used when you configure the counterpart tunnel on the peer VPN gateway. You can follow these directions to generate a cryptographically strong shared secret.
    • Routing options — Select Dynamic (BGP).
    • Cloud router — If you haven't already, create a new Cloud Router specifying the options as noted below. Alternatively, you can use an existing Cloud Router, if the Cloud Router does not already manage a BGP session for an interconnect attachment associated with a Partner Interconnect. If you choose an existing Cloud Router, you'll still create a new BGP session, but the Google ASN is the same. To create a new Cloud Router, specify the following details:
      • Name — The name of the Cloud Router. The name cannot be changed later.
      • Description — Optionally, type a description.
      • Google ASN — Choose a private ASN (64512 - 65534, 4200000000 - 4294967294). This Google ASN is used for all BGP sessions managed by the Cloud Router. The ASN cannot be changed later.
      • Click Save and continue.
    • BGP session — Click the pencil icon, then specify the following details. When you are done, click Save and continue:
      • Name — The name of the BGP session. It cannot be changed later.
      • Peer ASN — The private ASN (64512 - 65534, 4200000000 - 4294967294) used by your peer VPN gateway.
      • Advertised route priority — (Optional) The base priority Cloud Router uses when advertising the “to GCP” routes. For more information, see Route metrics. Your peer VPN gateway imports these as MED values.
      • Cloud Router BGP IP and BGP peer IP — The two BGP interface IP addresses must be link-local IP addresses belonging to a common /30 CIDR from the 169.254.0.0/16 block. Each BGP IP defines the respective link-local IP used to exchange route information. For example, 169.254.1.1 and 169.254.1.2 belong to a common /30 block.
  2. If you need to create more tunnels on the same gateway, click Add tunnel and repeat the previous step. You can add more tunnels later.
  3. Click Create.

gcloud


In the following commands, replace:

  • project-id with the ID of your project.
  • network with the name of your GCP network.
  • region with the GCP region where you need to create the gateway and tunnel.
  • (Optional) The --target-vpn-gateway-region is the region of the Classic VPN gateway to operate on. Its value should be the same as --region. If not specified, this option is automatically set. This option overrides the default compute/region property value for this command invocation.
  • gw-name with the name of the gateway.
  • gw-ip-name with a name for the external IP used by the gateway.

Complete the following command sequence to create a GCP gateway:

  1. Create the resources for the Cloud VPN gateway:

    1. Create the target VPN gateway object.

      gcloud compute target-vpn-gateways create gw-name \
          --network network \
          --region region \
          --project project-id
      
    2. Reserve a regional external (static) IP address:

      gcloud compute addresses create gw-ip-name \
          --region region \
          --project project-id
      
    3. Note the IP address (so you can use it when you configure your peer VPN gateway):

      gcloud compute addresses describe gw-ip-name \
          --region region \
          --project project-id \
          --format='flattened(address)'
      
    4. Create three forwarding rules. These rules instruct GCP to send ESP (IPsec), UDP 500, and UDP 4500 traffic to the gateway.

       gcloud compute forwarding-rules create fr-gw-name-esp \
           --ip-protocol ESP \
           --address gw-ip-name \
           --target-vpn-gateway gw-name \
           --region region \
           --project project-id
      
      gcloud compute forwarding-rules create fr-gw-name-udp500 \
          --ip-protocol UDP \
          --ports 500 \
          --address gw-ip-name \
          --target-vpn-gateway gw-name \
          --region region \
          --project project-id
      
      gcloud compute forwarding-rules create fr-gw-name-udp4500 \
          --ip-protocol UDP \
          --ports 4500 \
          --address gw-ip-name \
          --target-vpn-gateway gw-name \
          --region region \
          --project project-id
      
  2. If you haven't already, complete the following command to create a Cloud Router. Replace the options as noted below. Alternatively, you can use an existing Cloud Router, as long as the Cloud Router does not already manage a BGP session for an interconnect attachment associated with a Partner Interconnect.

    • Replace router-name with a name for the Cloud Router.
    • Replace [GOOGLE_ASN] with a private ASN (64512 - 65534, 4200000000 - 4294967294). The Google ASN is used for all BGP sessions on the same Cloud Router, and it cannot be changed later.
      gcloud compute routers create router-name \
      --asn google-asn \
      --network network \
      --region region \
      --project project-id
    
  3. Create the Cloud VPN tunnel with the following details:

    • Replace tunnel-name with a name for the tunnel.
    • Replace on-prem-ip with the external IP address of the peer VPN gateway.
    • Replace ike-vers with 1 for IKEv1 or 2 for IKEv2.
    • Replace shared-secret with your shared secret. The shared secret for the Cloud VPN tunnel must match the one used when you configure the counterpart tunnel on the peer VPN gateway. You can follow these directions to generate a cryptographically strong shared secret.
    • Replace router-name with the name of the Cloud Router you want to use to manage routes for the Cloud VPN tunnel. The Cloud Router must exist before you create the tunnel.

      gcloud compute vpn-tunnels create tunnel-name \
          --peer-address on-prem-ip \
          --ike-version ike-vers \
          --shared-secret shared-secret \
          --router router-name \
          --target-vpn-gateway gw-name \
          --region region \
          --project project-id
      
  4. Configure a BGP session for the Cloud Router by creating an interface and BGP peer. Choose one of the following methods:

    • To let GCP automatically choose the link-local BGP IP addresses:

      1. Add a new interface to the Cloud Router. Supply a name for the interface by replacing interface-name.

        gcloud compute routers add-interface router-name \
            --interface-name interface-name \
            --vpn-tunnel tunnel-name \
            --region region \
            --project project-id
        
      2. Add a BGP peer to the interface. Replace peer-name with a name for the peer, and peer-asn with the ASN configured for the peer VPN gateway.

        gcloud compute routers add-bgp-peer router-name \
            --peer-name peer-name \
            --peer-asn peer-asn \
            --interface interface-name \
            --region region \
            --project project-id
        
      3. List the BGP IP addresses chosen by the Cloud Router. If you added a new interface to an existing Cloud Router, the BGP IP addresses for the new interface should be listed with the highest index number. The Peer IP Address is the BGP IP you should use to configure your peer VPN gateway.

        gcloud compute routers get-status router-name \
             --region region \
             --project project-id \
             --format='flattened(result.bgpPeerStatus[].ipAddress, \
             result.bgpPeerStatus[].peerIpAddress)'
        

        Expected output for a Cloud Router managing a single Cloud VPN tunnel (index 0) looks like the following, where google-bgp-ip represents the BGP IP of the Cloud Router's interface and on-prem-bgp-ip represents the BGP IP of its peer.

        result.bgpPeerStatus[0].ipAddress:     google-bgp-ip
        result.bgpPeerStatus[0].peerIpAddress: on-prem-bgp-ip
        
    • To manually assign the BGP IP addresses associated with the GCP BGP interface and peer:

      1. Decide on a pair of link-local BGP IP addresses in a /30 block from the 169.254.0.0/16 range. Assign one of these BGP IP addresses to the Cloud Router in the next command by replacing google-bgp-ip. The other BGP IP address is used for your peer VPN gateway. You must configure your device to use that address, and replace on-prem-bgp-ip in the last command, below.

      2. Add a new interface to the Cloud Router. Specify a name for the interface by replacing interface-name.

        gcloud compute routers add-interface router-name \
            --interface-name interface-name \
            --vpn-tunnel tunnel-name \
            --ip-address google-bgp-ip \
            --mask-length 30 \
            --region region \
            --project project-id
        
      3. Add a BGP peer to the interface. Replace peer-name with a name for the peer, and peer-asn with the ASN configured for the peer VPN gateway.

        gcloud compute routers add-bgp-peer router-name \
            --peer-name peer-name \
            --peer-asn peer-asn \
            --interface interface-name \
            --peer-ip-address on-prem-bgp-ip \
            --region region \
            --project project-id
        

Follow-up steps

You must complete the following steps before you can use a new Cloud VPN gateway and tunnel:

  1. Set up the peer VPN gateway and configure the corresponding tunnel there. Refer to these pages:
  2. Configure firewall rules in GCP and your peer network as required. Refer to the firewall rules page for suggestions.
  3. Check the status of your tunnel, including forwarding rules.

What's next

Was this page helpful? Let us know how we did:

Send feedback about...