VPC configuration with Public and Private Subnet on AWS
Introduction:
The VPC is an acronym of Virtual Private Cloud. In the Amazon Web Service (AWS) environment, we can manage the Network Infrastructure in a secure way using the VPC (Virtual Private Cloud). This tutorial will cover VPC configuration with public and Private subnet on AWS.
Internet Gateway:
Allow Communication between two instances (or) communication between VPC to the Internet is known as IGW (Internet Gateway)
Subnet:
It is used to divide a single network into multiple networks using the different IP addresses is called subnetting.
Route Table:
In VPC infrastructure we can define how the traffic will flow in terms of using routing policy is called Route Table.
NAT Gateway:
Providing Internet to your private instance is called NAT Gateway.
The procedure of the VPC Creation:
Now we will see VPC configuration with Public and Private Subnet on AWS for that first we have to log in to your AWS console.
Now I need to create VPC for that click services and search VPC and click your VPC and create VPC and enter the VPC name enter the IP Range and click create.
Then I need to create subnets for Public1, Public2 and Private1 and Private2 for that click subnets then create a subnet and enter the name of the subnets then select VPC select region and enter then IP range then click create
Then the same way I will follow to create remaining subnets, finally the subnets are created
Then I have to route table for that click route table window click create route table enter the name of the routing table select the VPC and click create
The same way I follow to create another Route Table, finally, the routing table is created
Next, I will create an internet gateway for that click the internet gateway window then click create a gateway and enter the name of the gateway and click create. Finally, the gateway is created
Now we have attached the gateway to the VPC for that click actions and click attach VPC and select VPC and click attach then gateways are attached to our VPC.
Now I will create the Instance using a public subnet and access the instance via the Git Bash. For that, go to ec2 and click launch Instance and select the AMI and choose the tier than the configuration instance window select then network tab on you VPC and select the subnet and enable the auto-assign IP.
Now leave the default the specifications of the storage and enter the Instance name
Now go to the configure security group and enter the security group name and give all traffics and change the source to anywhere
Click the launch and create your keypair and for access your instance using SSH
Now I will define the routing policy of the public instance for that go to the route table window and select the Public route table and click routes and edit routes enter all traffic and put internet gateway ID to the target and click save
Now I will associate the subnets for that click associate subnets and edit then select the public subnets and click save.
Now I will take access to the public Instance for that go to download location of your local machine and right-click open Git bash and run the following command to take ssh after that I will check if the internet is connected or not
Now we will see how to create NAT instance and Private Instance and how to access Private instance through NAT instance
Go to AWS console and click launch instance and click community AMIs and search NAT and select any AMI for your NAT instance and do then same steps what you have done for the instance creation Then create the Instance for the private as follow the same way of the public instance creation Finally than instance is created
Now I will defines the routing policy for the private for that click route table and select private and click edit and click add route destination is all traffics and put a target for NAT instance ID then click save and associate the private 1 and 2 subnets.
Now I will access the NAT instance via the Git Bash. For that open Git Bash and take SSH on NAT instance and check then internet connectivity
Now I will access the Private Instance through the Private instance for that go to the AWS console and choose NAT instance click Connect tab then click SSH client and there you can see what are then steps to follow to connect then instance to then NAT instance
First I am given the permission of the private key
Then I have to take control of the Private instance through the NAT instance. Finally, I take access to the private instance through NAT instance
Now I will check the internet connection but the internet is not working
**If you want the internet connection you have to do some steps on NAT instance on AWS console for that open AWS console choose NAT instance click actions and click networking tab then click change source to destination check then enable stop and save. Now check the connection on a private instance **
Now the internet connection is working on the private Instance
With this method, VPC configuration with Public and Private Subnet on AWS.