Josh Unger
Josh Unger

Reputation: 7163

Create route between two networks in Google Cloud Compute Engine

I created two networks in Google Cloud Compute Engine. One called front using 10.200.166.0/26 and another called back using 10.200.165.0/26. I was planning to have my web server in front and my database server in back. But, I can't figure out how to create a route between the two networks. Is this possible? If so, what is the gcloud command?

Upvotes: 2

Views: 4750

Answers (4)

kurkop
kurkop

Reputation: 530

You need to follow the next steps:

  1. Adding networks and subnetworks
  2. Adding ssh and icmp rules
  3. Create gateways
  4. Reserve static ips
  5. Create forwarding rules for both vpn gateways
  6. Create tunnels
  7. Create static routes
  8. Create instances

An example of that in terraform: https://github.com/kurkop/terraform-labs/tree/master/vpn2vpn

Upvotes: 0

Avinoam Meir
Avinoam Meir

Reputation: 507

You can use now network peering, which basically allow to pass traffic between the two networks.

Upvotes: 0

Siddharth Gupta
Siddharth Gupta

Reputation: 11

You can do that by setting up a VPN gateway in each of them and specifying the other one as the destination gateway IP.

  1. Create a preshared key on a site like https://www.random.org.
  2. Go to your Networking section -> VPN -> Create VPN Connection
  3. Duplicate open this page in another tab
  4. In first tab, create a new public IP for your VPN connection and put the preshared keys in the details.
  5. Do the same in the second tab.
  6. Now give the ip that you've created for the 'front' gateway as a tunnel in the 'back' one and also do vice-versa.
  7. Specify local and remote routes in both tabs using data from each other.
  8. Click create on both places at the same time. Wait for a minute and you're done!

Upvotes: 1

Faizan
Faizan

Reputation: 1967

In GCE in order to communicate between two networks you need to use the public IP assigned to the instance. You will not be able to communicate between two networks using private IPs. You can find more information on the GCE networks in this article. However, keep in mind that communication through public IP is considered as egress traffic and might be charged depending on the traffic type. You can refer to this article for more information on egress charges.

If you need to create a static IP and route the traffic to that static IP, you can do that using a combination of routes and an instance's --can-ip-forward ability to add an IP address as a static network IP address that will than map to your desired virtual machine instance. You can find more information and the steps in this article.

Upvotes: 4

Related Questions