Connecting Two VPCs(Different Locations based on aws or gpc) with Cross-Region VPC Peering.

Introduction:

mridul
3 min readAug 22, 2023

In today’s cloud-centric world, businesses rely on the flexibility and scalability offered by cloud platforms to build and manage their applications and services. In this way, Virtual Private Clouds (VPCs) have revolutionized the way organizations build and manage their network infrastructure. VPCs offer a secure and isolated environment in the cloud, allowing businesses to create resources like virtual machines, databases, and containers while maintaining control over their network architecture. Google Cloud Platform (GCP) AWs and Azure so many companies provide a robust networking infrastructure that allows you to create and manage Virtual Private Clouds (VPCs) to isolate and secure your resources. One common challenge faced by organizations is connecting VPCs that are located in physically different regions, effectively bridging the gap between geographically separated cloud environments. One powerful feature both companies offers is VPC peering, which enables you to connect VPCs from different projects or regions, allowing them to communicate securely and efficiently.

In this blog post, we’ll delve into the concept of VPC peering and guide you through the process of connecting two VPCs using this method.

Understanding VPC Peering and Cross-Region Peering

VPC Peering is a networking feature offered by cloud providers like Amazon Web Services (AWS) and Google Cloud Platform (GCP). It allows two VPCs to communicate with each other as if they were in the same network, even if they belong to different AWS regions or GCP zones. This enables organizations to extend their network architecture across geographic regions without the need for complex and costly solutions like Virtual Private Networks (VPNs) or Direct Connect.

When it comes to physically distant VPCs, Cross-Region VPC Peering is the solution. It allows VPCs in different geographical locations to connect and share resources securely, just as if they were in the same physical location. This can lead to numerous benefits for businesses, such as redundancy, high throughput, disaster recovery, and optimized latency for globally distributed applications. With VPC peering, you can share resources, transfer data, and facilitate seamless communication between VPCs without exposing your traffic to the public internet

Steps to Connect Two VPCs with VPC Peering: Here’s a step-by-step guide to connecting two VPCs using VPC peering in Google Cloud:

  1. Create VPCs and VM: Begin by creating two separate VPC networks, each in a different project create two VM. Define the IP ranges for each VPC.
  2. Enable VPC Peering: In the Cloud Console, navigate to the VPC Network section. Select the VPC network you want to peer from and click “VPC Peering.” Create a new peering connection and specify the name, network, and project of the target VPC and reverse it again. You see the peer connection is in active mode. It means you successfully connected to VPC.

Now go to VM and install the following tools to check the connection

VM-DB:


# step-1 update the vm
sudo apt update -y


#step-2 cheak the connection
#for show the ip addess which aviabile
ip addr
# for cheak interaction is working or not install this tools
sudo apt install telnet -y
sudo apt insatll tcpdump -y
#install nginx for data pass cheaking in the vpc-DB to vm-api
sudo apt install nginx -y
#for numnginx in port 80 it also run default port [80]
sudo tcpdump -i ens4 -v port 80

#step-3 cheak the connection
ping 10.105.0.2 -c 3
#from vpc-mridul-api
sudo tcpdump

#step-4 connection cheak
#from vm-db call to get data
telnet 10.0.0.2 80
# usign the below command we can see the port and address where communtiona re built
wget 10.0.0.2:80

VM-API:


# step-1 update the vm
sudo apt update -y

# step-2 insatll telnet in vm for cheak the connection

#for show the ip addess which aviabile
ip addr
# for cheak interaction is working or not
sudo apt install telnet -y
sudo apt insatll tcpdump -y

#step-3 cheak the connection

#from vpc-mridul-api
ping 10.0.0.2


#from vm-db call to get data
telnet 10.0.0.2 80
# usign the below command we can see the port and address where communtiona re built
wget 10.0.0.2:80

Project Github link

  • I hope you find this article interesting and learned something useful.
  • Thanks for reading this article.

— — — — — — — — Happy Coding — — — — — — — — —

--

--