# Demonstration of VPC Peering.

**VPC peering** is a valuable networking connection that enables two distinct VPCs to securely share resources creating the illusion of being on the same network.

This capability is crucial as it provides a cost-effective solution for resource sharing between multiple VPCs located in the same or different regions eliminating the need for internet gateways. Additionally, by not relying on public IP addresses or internet access VPC peering enhances security measures.

### <mark>Let's begin the Demonstration.</mark>

Step 1: Go to the **AWS management console** search for **VPC**, and click on it.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489776937/2882fd1c-5db7-402f-a2c7-2db2ad4d6857.png align="center")

Step 2: Click on **Create VPC.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489783377/fc3f6fb5-bdcb-4086-9ce8-a21f62414c62.png align="left")

Step 3: From **VPC settings**

* select **VPC only**
    
* Enter the name of VPC. For now, say **<mark>“my-vpc1"</mark>**
    
* Enter IPv4 CIDR <mark>10.0.0.0 /16</mark>
    
* Click on **Create VPC**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489796705/65038927-fd90-473d-8c6e-f6a654b4f161.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489799319/4d25d2db-6cf9-4edc-bda2-6611b8e7364c.png align="left")

Step 4: From the **Dashboard**, select **Subnets**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489804791/b838d55f-3ee7-4618-989d-d8066f4bef82.png align="left")

* click on **Create subnet**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489808403/a9c5f586-0697-4edc-af94-b7d259030de9.png align="left")

Step 5: From VPC ID select <mark>“my-vpc1"&nbsp;</mark> 

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489812653/cc23ffbc-2c23-458c-b479-fc697dcc50d5.png align="center")

* Give a name to the subnet. For now let’s say, **<mark>“subnet01”</mark>**
    
* Select an Availability zone: "**us-east-1a"**
    
* Enter the CIDR block say, **<mark>10.0.1.0/24</mark>**
    
* Click on **Create subnet.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489816741/c1dd37b7-22d3-439d-99b0-dee3214a3667.png align="center")

Step 6: From the **Dashboard**,  Select **Internet gateway**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489819819/a43ab527-0c31-40e4-9262-0495c1ae6a0e.png align="left")

* click on **Create Internet gateway**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489824359/e89d53c0-7544-4c91-91d4-1be5596146f6.png align="left")

Step 7: In the Internet gateway settings

* give a Name tag, let’s say <mark>"</mark>**<mark>internet-gateway"</mark>**
    
* click on **Create Internet gateway**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489946632/ff07b6d5-0b83-4aee-b37c-774d06654ca0.png align="center")

Step 8: On the top, you can see the <mark>“</mark>**<mark>Attach to a VPC”</mark>** message, **Click on it** or you can attach it from the **Action.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489832587/3a722505-e89a-450e-9dae-c364cd6226cb.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489839619/52af0719-8348-42cf-805a-12af2cd56b2a.png align="center")

Step 9: We will create another VPC. From the dashboard, Select **“Your VPCs”**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490035226/95339e95-7f7d-4670-95ff-895c8d15239a.png align="left")

* Click on **Create VPC**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490044829/529aea0c-2099-4db8-beda-24f0625cd34c.png align="left")

* under **VPC Settings**, Select **VPC only**
    
* Enter the IPv4 CIDR block say, **<mark>192.0.0.0/16</mark>**
    
* Click on **Create VPC.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490060398/5087eb01-bc5d-406c-a640-6a560fe683ae.png align="center")

Step 10: From the dashboard select **Subnets**, click on **Create subnet**

* under VPC ID select **“my-vpc2"**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490070714/f0429550-4363-48a9-a128-e263bdc9ae69.png align="center")

* Give a name to the subnet. For now let’s say, <mark>“subnet2”</mark>
    
* select an Availability zone say, **"us-east-1a"**
    
* Enter the CIDR block say, <mark>192.0.1.0/24</mark>
    
* Click on **Create subnet**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490090435/7307804f-21ae-4c71-9713-627abe805ffc.png align="center")

Step 11: From the dashboard, select **“Peering connections**”

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490099693/2cb4fac9-4ad7-412b-9f91-fffcf31d5310.png align="left")

* click on **Create peering connection**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490166766/dfc997f9-c824-44bf-8fcb-efd33eba4208.png align="left")

Step 12: In peering connection settings

* give a name to the connection say, **<mark>“my-connection"</mark>**
    
* Select **“my-vpc1”** In the **VPC ID (Request**er)
    
* Select **“my-vpc2”** in the **VPC ID (Accepter)**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490172314/84434998-88d6-447e-9119-9b6ad94c4c7e.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490182005/a5beacb4-b9f7-4a8b-836a-daf967e88583.png align="center")

* click on **Create peering connection**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490202534/02188c15-796b-4f2b-9aa1-a49e83d5bc57.png align="left")

step 13: Now you can see **Actions** in “**my-connection"**

* Click on it and **Accept request**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490210109/d4bbafe9-7bca-4254-98a2-c4ff95a567fa.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490219865/9b2afbd3-a7ff-4575-aca8-9c2b2f7601f8.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490227208/de4b2a2f-3edc-481c-924d-f24617f81b99.png align="center")

Step 13: From the dashboard, Select **"Route tables"**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686489857190/91b6f42a-a3c3-4209-b802-cb2e0059a44b.png align="left")

step 15: In the **Route table settings**

* Give a name say, **<mark>“routeTable1”</mark>**
    
* Select “**my-vpc1"**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490004114/63d4561d-ad29-4a21-847d-99a29926fcd8.png align="center")

* Click on **Create route table**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490012057/713ca690-fd69-4dbf-8993-b65aa362aa17.png align="left")

step 16: Select **“routeTable1”**, from the **Route tables.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490376368/8b08f506-5bed-4b1c-9c9f-c2348c96beb7.png align="center")

* Click on **Routes**
    
* click on **Edit routes**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490383103/191abbc2-da3c-4138-b074-57137a31ced4.png align="center")

* click on Add route
    
* under Destination enter **<mark>0.0.0.0/16</mark>** and select the **<mark>Internet gateway</mark>** in Target.
    
* Similarly, add **<mark>192.0.0.0/16</mark>** in Destination and select **<mark>Peering connections</mark>**
    
* Click on **Save changes**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490389932/efd47a0e-cc4a-48d9-9858-5d828659be04.png align="center")

Step 17: Select the **Subnet associations**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490401960/5dff4d66-066a-4dc0-9c13-1b8999fc745a.png align="center")

* click on **Edit subnet associations**
    
* select the "**subnet01"**
    
* click on **Save associations.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490410261/1cf032f4-9de1-4e57-840b-27f7c0895d42.png align="center")

Step 18: we need to create another route table. so, from the dashboard, Select **Route table.** Under route table settings

* Give a name to the table say, **<mark>"routeTable2</mark>**<mark>"</mark>
    
* select the second VPC created, **“my-vpc2”**
    
* Click on **Create route table**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490300967/384f4ec7-f075-4244-b465-3696b71b3a8d.png align="center")

Step 19: Select the **routeTable2**

* click on **Routes**
    
* click on **Edit routes**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490313391/5c27dea8-e4d2-4955-8258-0250c52ae680.png align="center")

* click on **Add route**
    
* enter **<mark>10.0.0.0/16</mark>** in the **Destination** and select **<mark>pairing connections</mark>** in the **target.**
    
* click on **Save associations**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490327843/de5ffb2a-9043-40fd-b637-52e56e2cd41e.png align="center")

* click on the **Subnet associations**
    
* click on **Edit subnet associations**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490336046/7585f37e-9500-45e5-bbfe-f7d5ce15884b.png align="center")

* select the **subnet2**
    
* click on **Save associations.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490343674/2cf62831-25e7-40c0-9bec-4fbcff714c17.png align="center")

Step 20: From the **AWS management console,** Search **EC2** and **click on it.**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490433776/a13b5433-eeff-4359-8f0c-f771257aa1fc.png align="center")

Step 21: Click on **Launch instance**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490439026/9460c3d0-e5fc-4645-8031-14c75d0ee3d7.png align="left")

Step 22: Give a name to the instance, say **<mark>"myserver1"</mark>**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490443705/f40ddf56-015a-4078-9aa2-28e36b5e5de6.png align="center")

* select the existing **key pair** or **create a new key pair**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490446068/3054c980-0412-4a23-84fc-33b8f4684ddf.png align="center")

Step 23: in the network settings, click on **Edit**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490930971/58e0bbf3-08d4-46a8-b8ca-950f14faffb0.png align="center")

* Select your first VPC, **“my-vpc1”**
    
* select the subnet, **“subnet01”**
    
* **“Enable”,** Auto-assign public IP
    
* Leave the other setting as the default
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490453076/81e3ede3-0c9c-4d16-b2d1-d62357deb01e.png align="center")

step 24: Click on **launch instance**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490456831/fb7d8b29-44a0-4ae4-9457-5760a17899bf.png align="left")

step 25: We will create another instance named **“myserver2”**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490460166/631b4b8f-875d-44b1-8940-3ed4336b7b9e.png align="center")

* select the **Key pair (login)**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490463961/322b8092-9514-4ae9-b6ef-423b6da68a82.png align="center")

Step 26: In the network settings, click on **Edit**

* select the second VPC created, **“my-vpc2"**
    
* select the subnet, **“subnet2”**
    
* **Disable,** Auto-assign public IP
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490805042/9d445824-c7dc-4049-882d-0229c6497360.png align="center")

* Under **Firewall(security groups)**, Select the **create security group**
    
* You can give the name of the Security group and Description or leave it as the default
    
* In the **inbound security groups rules**
    
* Under **Type** select **“All traffic” or “All ICMP”** and under **Source type** select **“Anywhere”**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490471905/000ca6a3-06f8-4200-8a32-2b1ac2aa0ef1.png align="center")

Step 27: Click on **Launch instance**

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686490559902/dfc8f25c-6311-420a-a3dd-92b9bf20d890.png align="left")

* From the Instance summary of **“myserver2”,** Copy the **Private IPv4 addresses**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686491010865/3b8c4a35-9046-4da6-a4a1-93914892d358.png align="center")

Step 28: In the **Instances,** you can see the two servers running

* select the **“myserver1”**
    
* Click on **Connect,** on the right side of the instances.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686491015209/b950a27a-2861-4629-84aa-1f5653aab5d8.png align="center")

* Select the **EC2 Instance Connect**
    
* Click on **Connect.**
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686491018455/7bce2360-db61-49c5-887e-b2d6a2e43187.png align="center")

Step 29: **Ping** the **my-server2** private IP address.

```bash
ping <private ip addresses>
```

Step 30: you should see the following output.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1686491024976/42796558-a0e7-45d1-a518-48fd4e0aba73.png align="center")

### Congratulations!!!

You have completed the Demonstration of VPC Peering.
