How to Create a VPC with Public and Private Subnets

Share via:

Dear Readers,

In this article, we will see the following Realtime Usecase.

Realtime Usecase :
My Client  wants to launch their Websites publicly along with its Database Servers at the back end.
Establish network connectivity between Web Servers & Database Servers.
Note: No need of Public Access for Database Servers Ensure Only Websites can access from Public Network.

Steps to Follow :
  1. Logging to AWS Account.
  2. Create VPC”ktexpertsvpc” and assign IP range “192.168.0.0/16”
  3. Create two subnets inside the VPC and assign IP range for both subnets
  4. Create Internet Gateway for providing internet to the subnet -1
  5. Create an Route Table
  6. Connect Root Table “ktexperts-RT1”  to subnet 1 “192.168.1.0/24  – ap-south-1a (subnet-1) – (Public Subnet)
  7. Connect Root Table “ktexperts-RT1”  to Internet Gateway “IGW-ktexperts”
  8. Rename default Route Table to “ktexperts-RT2” and connect to private subnet
  9. Create Web Server (Windows) inside public subnet
  10. Create Database Server (Windows) inside private subnet
  11. Connect to web server through Remote Desktop Connection
  12. Connect to Data Base Server from Web Server
  13. Access Web Server from Database Server

 

1. Logging to AWS Account

First, we need to AWS Console page by using below link.

https://aws.amazon.com/console/

Click on sign in to Console button.

Logging to aws account

Provide username and password then click on sign in.

Enter to AWS Management Console

We can see the AWS Management Console Dashboard.

Go to Services, under the Networking & Content Delivery click VPC service to open.

2. Create VPC”ktexpertsvpc” and assign IP range “192.168.0.0/16”

Go to your VPC’s here It’ showing one default VPC.

Click on Create VPC  to create an new VPC.

Give name for VPC “ktexpertsvpc” in the Name tag and IP range “192.168.0.0/16” in the IPV4 CIDR block field then choose No IPVS CIDR. Block (here is no IPV6 CIDR BLOCK) .

Choose default option for Tenancy then click on Create.

Note:

IPV4 is the default.

Tenancy we can choose either default(share to others) or dedicated( can’t share to others).

The VPC has been created successfully then click on close.

We can see the VPC “ktexpertsvpc” which was created earlier.

3. Create two subnets inside the VPC and assign IP range for both subnets

As a first we need to create 2 subnets.

Create First Subnet 

Go to Subnets and Click on Create Subnet to create an new subnet.

Note :

By default subnets are private.

by default we can see 3 subnets are will be available.

Choose your VPC “ktexpertsvpc” then click on required vpc.

Choose Required Availability zone “ap-south-1a” for subnet.

Give IP range “192.168.1.0/24” for subnet in the IPV4 CIDR Block and mention Name tag with proper meaning to identify easily “192.168.1.0/24  – ap-south-1a (subnet-10)” then click on Create.

We can subnet “192.168.1.0/24  – ap-south-1a (subnet-1)” which was created earlier.

Create Second Subent

Click on Create Subnet to create another new subnet.

Provide Required details

Give VPC name “ktexpertsvpc”,Availability Zone “ap-south-1b” , IP range “192.168.2.0/24 “in the IPV4 CIDR Block and Name tag “192.168.2.0/24  – ap-south-1b (subnet-2)” then click on Create.

4. Create Internet Gateway for providing internet to the subnet -1

Go to Internet Gateways and click on Create Internet gateway to create an new internet Gateway.

Note

By default there is one internet gateway will be available.

Specify Name tag “IGW-ktexperts” for internet gateway and click on Create.

The internet gateway has been created successfully and click on Close.

By default any created Internet Gateway is in Detached state.

Attach Internet Gateway “IGW-ktexperts” to your VPC.

Choose your VPC and click on Attach.

Now, the Internet gateway has been attached to VPC.

5. Create an Root Table 

Go to Root Tables and click on Create route table.

Note :

By fault there is two root table will be here

  1. First Route Table is Connected to Default VPC.
  2. Second Route Table is Connected to Your VPC.

Specify Name tag “ktexperts-RT1” and choose your VPC and click on create.

The route table has created with following ID then click on Close.

we can see the created root table “ktexperts-RT1”.

6. Connect Root Table “ktexperts-RT1”  to subnet 1 “192.168.1.0/24  – ap-south-1a (subnet-1) – (Public Subnet)

 Select Root table “Internet-RT” and go to subnet Associations then click on Edit subnet associations.

Checked subnet 1  ID “192.168.1.0/24  – ap-south-1a (subnet-1)” and click on Save.

We can see the the route table has been connected to subnet 1 “192.168.1.0/24  – ap-south-1a (subnet-1) – (Public Subnet).

7. Connect Root Table “ktexperts-RT1”  to Internet Gateway “IGW-ktexperts”

Go to Routes and click on Edit Routes.

Click on Add route.

Choose Internet Gateway option in the Target.

Select your Internet Gateway “IGW-ktexperts”

Specify Destination with “0.0.0.0/0” and Target then click on save routes.

Note

Wherever you want internet you must choose IP called 0.0.0.0/0.

We can message like Routes successfully edited then click on close.

The route table has been connected to your Internet Gateway “IGW-ktexperts” successfully.

8. Rename default Route Table to “ktexperts-RT2” and connect to private subnet

Use default Route Table as second Route Table.

Connect Root Table “ktexperts-RT2”  to subnet 1 “192.168.2.0/24  – ap-south-1b (subnet-2) – (Private Subnet)

 Select Root table “ktexperts-RT2” and go to subnet Associations then click on Edit subnet associations.

Checked subnet 1  ID “192.168.2.0/24  – ap-south-1b (subnet-2)” and click on Save.

We can see the the route table has been connected to subnet 2 “192.168.2.0/24  – ap-south-1b (subnet-2) – (Private Subnet).

 

9. Create Web Server (Windows) inside public subnet

We can create web server (windows) by using below link.

How to Create Webserver On Windows

We can see the Web Server which was launched.

10. Create Database Server (Windows) inside private subnet

We can create Database Server by using below link.

Launch Database  Server (windows)

We can see the Database Server which was launched.

 

11. Connect to web server through Remote Desktop Connection

We can use Remote Desktop Connection for connecting to Windows Server.

When connected, the desktop Windows server is displayed.

12. Connect to Data Base Server from Web Server

Go inside the web server.

Select Database server,copy the private IP.

Go to search bar,Type Remote Desktop Connection

Once open Remote Desktop Connection we specify Database server private IP which was coped and click on Connect.

Here we need to specify Username and Password of database server

Copy the Username and password of database server.

Specify username and password of database server which was copied and click on ok.

We can see database server

we have connected from web server.

13. Access Web Server from Database Server

Select Web Server and copy the Public IP.

Go inside the internet explorer of database server and search public IP of web server which was copied.

We can see content of web server inside the database server.

We have communication between web server to database and database server to web server.

 

Thank you for giving your valuable time to read the above information.
Follow us on 
Website  www.ktexperts.com
Facebook Page KTexperts
Linkedin Page : KT EXPERTS

Follow Me
Ramesh’s Linkedin : Ramesh Atchala

Share via:
Note: Please test scripts in Non Prod before trying in Production.
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Add Comment