Google Cloud VPN
This tutorial provides information and examples of how to configure IPsec VPN between Cloudflare Magic WAN with a GCP Cloud VPN.
You need to have a GCP VPN gateway created in your GCP account. This is needed to route traffic between your GCP virtual private cloud (VPC) and Cloudflare Magic WAN. Refer to the GCP documentation ↗ to learn more about creating a Cloud VPN gateway.
A Classic VPN Gateway is required to support static routing. Route tables will also need to be manually configured to allow the routing between the VPN and Cloudflare Magic WAN to work. Refer to GCP routing options ↗ to learn more about GCP VPC routing.
- Go to Network Connectivity > VPN.
- Select the Cloud VPN Gateways tab > Create VPN Gateway.
- Give your gateway a descriptive name.
- Choose the network you want to connect to with this Cloud VPN Gateway (VPC).
- Select a region where this Cloud VPN Gateway should be located.
- Choose IPv4 as the IP traffic type that will flow through this Gateway.
- Go to Network Connectivity > VPN.
- Select the Cloud VPN Tunnels tab > Create VPN Tunnel.
- Select the VPN Gateway you have created > Continue.
- Give your tunnel a descriptive name.
- For Remote Peer IP Address, use one of the public anycast Magic WAN IPs given to you by your account team.
- In IKE version, select IKEv2.
- You can generate an IKE pre-shared key, or add one you already own. If you generate one during this set up, keep it somewhere safe since you will need it in other steps to finish setting up Magic WAN and GCP.
- Choose Route-based as routing option.
- In Remote network IP range define the network you are going to expose to GCP via Cloudflare Magic WAN.
- Repeat the same process using your second Cloudflare anycast IP.
Static routing is necessary to route traffic between your VPN and Cloudflare Magic WAN. Follow these steps to create them for your VPC. Refer to VPN route documentation ↗ to learn more about VPN routing.
- Go to VPN Network > Routes.
- Select Route Management.
- Create a route.
- Choose the VPC network you want to use for that route.
- In Route type select Static Routing.
- In IP Version select IPv4.
- Configure the network you want to expose to your VPN in the Destination IPv4 Range.
- Choose a priority for your static route.
- (Optional) You can link that route to a specific instance tag, so only impacted instances will use that route.
- In Next hop select the VPN tunnel you created previously.
- Select Create.
After configuring the Cloud VPN gateway VPN and the tunnels as mentioned above, go to the Cloudflare dashboard and create the corresponding IPsec tunnels and static routes on the Magic WAN side.
- Refer to Add tunnels to learn how to add an IPsec tunnel. When creating your IPsec tunnel, make sure you define the following settings:
- Tunnel name:
tunnel01
- Interface address: The IPsec tunnel inner
/30
CIDR block. For example,169.254.244.2
. - Customer endpoint: The IP address from GCP VPN tunnel outside IP address. For example,
35.xx.xx.xx
. - Cloudflare endpoint: Enter the first of your two anycast IPs.
- Pre-shared key: Choose Use my own pre-shared key, and enter the PSK you created for the GCP VPN tunnel.
- Health check type: Choose Reply
- Health check destination: Choose custom and set the IP corresponding to the interface address for the tunnel
- Health check direction: Choose Bidirectional
- Replay protection: Select Enabled.
- Tunnel name:
- Select Save.
- Repeat the above steps for
tunnel02
. Chose the same prefix, but select the second IPsec tunnel for Tunnel/Next hop.
The static route in Magic WAN should point to the appropriate virtual machine (VM) subnet you created inside your GCP virtual private cloud. For example, if your VM has a subnet of 192.168.192.0/26
, you should use it as the prefix for your static route.
To create a static route:
- Refer to Create a static route to learn how to create one.
- In Prefix, enter the subnet for your VM. For example,
192.xx.xx.xx/24
. - For the Tunnel/Next hop, choose the IPsec tunnel you created in the previous step.
- Repeat the steps above for the second IPsec tunnel you created.