Problem statement:
process of connecting DB server using NAT gateway using VM server
Different services that used as part of NAT gateway for instance are:
- NAT gateway is used to connect the internet from instances. It prevents the internet from connecting to instances directly.
- VPC
- subnets
- routing table
- internet gateway
- VPC
- Elastic IP
Brief introduction about the above-mentioned services
Creating a VPC
using NAT gateway
As detailed in previous go to amazon web services
1. Create a VPC
Now go to subnets and create a subnet according to the details mentioned below
Create another subnet as AWS-NAT using below details
Use modify auto-assign IP and enable IPv4
2. Create a NAT gateway and select subnet
Create a NAT gateway using above details don’t use a DB server which is AWS-NAT server which will directly expose to the internet, also allocate Elastic IP which will create an IP at the NAT gateway elastic IP will be automatically created
3. Create a routing table and add NAT subnet to it
·
Add NAT subnet to the routing table in edit subnet association.
· don’t enable second subnet which will directly add instance to the internet gateway which is a security issue.
Now edit routes and add destination as 0.0.0.0/0 and select the target as NAT gateway and save
Create another routing table for second subnet and edit routes and subnet association sections as below and create an internet gateway for the second subnet
4. Deploy VM in public subnet and server in a private subnet
Now create an instance with details given below
Now select AWS-server and network interface IP as
10.1.1.100, add storage and tags
Now create a new security group as details mentioned above and launch the instance
Create a new
key pair or download an existing keypair
Again, create another instance DB1 server
Under the network interface give primary IP as
10.1.5.100, add storage and tags. give security group which was already created
and download keypairs
5. Try to connect DB1 server using public IP and it should fail
Now copy public DNS of DB1 and open putty
We need to convert the key pairs into PPK format for putty. So, we need to use putty gen to convert the PEM files
copy public DNS in the hostname and go to SSH select keypairs which are in PPK format and open
It showed be appear as below
In the scenario, we can say that NAT gateway was not
allowing to connect DB1 directly
Now try to connect VM1 using the same process
It has connected to the VM1 using internet gateway
directly
Now use following commands for connecting to DB1 from VM1
Command:
· $ sudo su - (for the root user)
6. Now connect to DB1 using VM1
Ping to DB1 using IP 10.1.5.100 it
should ping
Now to connect to DB1 using PEM file for authorization use below steps
· Open PEM file using visual studio code
Copy entire private key in the pem file and create a file in VM1 using nano editor
· Nano AWS.pem
paste in the file and save it for use ctrl+o and exit use ctrl+x
We need to change read and write permissions for that use command as
· Chmod 400 AWS.pem (read and write permissions)
Now connect DB1 from VM1 using the command below
· SSH -I AWS.pem ec2-user@10.1.5.100 (connecting and authorization)
7. Now ping www.google.com and it should work
No comments:
Post a Comment