Connecting VPCs through VPC Peering
What is VPC Peering?
VPC Peering is a networking connection between two VPCs that enables you to route traffic between them using private IP addresses. Instances in either VPC can communicate with each other as if they were within the same network, allowing for seamless data sharing and management across VPCs.
Key Benefits of VPC Peering:
Cost-Effective: VPC Peering is typically less expensive than setting up a VPN or other networking solutions.
Performance: Provides low-latency, high-bandwidth connectivity between VPCs.
Security: Communication is private and does not traverse the public internet, enhancing security.
Simplicity: Easy to set up and manage within the AWS Management Console.
Steps to Create VPC Peering Connection:
Initiate VPC Peering Connection:Sign in to AWS, navigate to VPC, select Peering Connections, create a peering connection, and configure it between VPC A ( test-vpc-1) and VPC B (test-vpc-2).
Step 1:
Create two VPC's named as test-vpc-1 and test-vpc-2. Enter the IPv4 CIDR 12.0.0.0/16 and 13.0.0.0/16 respectively and create VPC.
Step 2:
Create Two subnets named as test-subnet-1 and test-subnet-2. Enter IPv4 CIDR 12.0.1.0/24 and 13.0.1.0/24 respectively and create subnet.
Step 3:
Create Two route tables named as test-rt-1 and test-rt-2. Select route table one by one and in actions select subnet association and select subnets as shown.
step 4:
Click the Subnet associations with the created route table for the Public subnet. then, click "Edit subnet associations" under Subnet associations
Step 5:
Create Internet Gateway and in upper green bar click attach to a VPC and select test-IGW-1 and test-IGW-2 then attach.
Step 6:
Go to the route table and select test-rt-1 and test-rt-2 then, Edit Route as below.
Now, We can see that the Resource Map
Accept the Peering Connection:Sign in to the account owning VPC B, navigate to VPC, find and accept the pending peering connection.
Step 7:
In the navigation pane, choose Peering connection. Name your Peering as test-peering-from-vpc1-to-vpc2. Select test-vpc-1 as Requestor and test-vpc-2 as Acceptor and Create Peering Connections. Then select your created peering and in right click on actions then accept the request.
Update Route Tables for VPC 1:In the VPC dashboard, select the route table for VPC A, add a route to the CIDR block of VPC B, and save.
Step 8:
Now from navigation bar select route tables , select the test-rt-1 then click on actions and select edit route and add route in destination enter the CIDR of test-rt-2 and in target select peering connections and click on save changes.
Update Route Tables for VPC 2:Select the route table for VPC B, add a route to the CIDR block of VPC A, and save.
Step 9:
Now add route in test-rt-2 and in destination enter the CIDR of test-rt-1 and in target select peering connection and click on save changes .
Modify Security Groups for VPC 1: In the VPC dashboard, update inbound and outbound rules for VPC A’s security group to allow traffic to/from VPC B’s CIDR block.
Step 10:
Go in security Groups and select SG-test-vpc-1 add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the both CIDR of test-vpc-1 and test-vpc-2.
Modify Security Groups for VPC B: Update inbound and outbound rules for VPC B’s security group to allow traffic to/from VPC A’s CIDR block.
Step 11:
Go in security Groups and select SG-test-vpc-2 add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the both CIDR of test-vpc-1 and test-vpc-2.
Test Connectivity: Launch instances in both VPCs and verify connectivity using tools like ping or SSH.
Step 12:
Now all your instances are launched. Select the instance test-ec2-1 and go in security tab then add rule in inbound rules. In type enter All ICMP-IPv4 and in source write the CIDR of test-vpc-2.
Repeat the same process for test-ec2-2 in source write the CIDR of test-vpc-1 and save rule.
Step 13:
Now ping the private IPv4 of test-ec2-1 from test-ec2-2 to check connectivity.
Now ping the private IPv4 of test-ec2-2 from test-ec2-1 to check connectivity.
Successfully Completed VPC Peering!!
Subscribe to my newsletter
Read articles from Utkarsh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Utkarsh Gupta
Utkarsh Gupta
🚀 Hi everyone! I'm Utkarsh Gupta, IAM Consultant. I am very passionate for all things DevOps. Right now, I'm learning and working on some cool projects and I can't wait to share what I'm learning with you all! 🛠️ Here's what's in my toolbox: Linux Docker Kubernetes Jenkins AWS Python Prometheus Grafana Ansible Terraform Join me as we explore AWS DevOps together. Let's learn and grow together in this ever-changing field! 🤝 Feel free to connect with me for: Sharing experiences Friendly chats Learning together Follow my journey on Hashnode and LinkedIn for daily updates. Let's dive into the world of DevOps together! 🚀 #DevOps #AWS #DevOpsJourney #90DaysOfDevOps