You can deploy AWS resources into your own virtual network using Amazon VPC. This tutorial explains what Amazon VPC is, shows you how to deploy a VPC within AWS in steps. Also explained is how to deploy an AWS VPC, including both public and private subnets. The article continues by describing how the route table, internet gateway and NAT are used and then demonstrates how to set up a VPC Peering between two VPCs within AWS.
⚡ QUICK ANSWER
An Amazon VPC is a virtual network within AWS. You can deploy resources into this network. You can define an IP range, establish subnets and manage a network using route tables, an internet gateway and network ACLs. Public subnets can communicate directly with the internet whereas private subnets communicate via NAT, and are therefore protected.
Are you searching for the best platform to obtain information on Amazon VPC Management? Are you excited at the prospect of completing a highly regarded Certification Course provided by India’s Leading AWS Training institute? Well you have found the Right Path!
By following the Below Tutorial, you will be able to Understand in depth information on Amazon VPC Management. Simply follow all Tutorials from India’s Leading Best AWS Training institute and become a Pro AWS Developer.
In this article, you will learn:
Using Amazon Virtual Private Cloud (Amazon VPC), you can deploy resources onto a virtual network that you define. Like a physical network that you would manage in your own data centre, it benefits from the scalability of Amazon Web Services cloud infrastructure.
Amazon VPC is the OSI model networking layer for Amazon EC2.
This tutorial will demonstrate how to design your infrastructure or private network.
A VPC is assigned a private IP range. This can then be sub-divided into subnets in various Availability Zones. Traffic from these subnets can then be directed using route tables. An internet gateway links public subnets to the internet. Furthermore, a NAT can be utilised so that private subnets can communicate externally but are not themselves externally accessible.
In order to design a secure VPC, we will first deploy a DemoVPC (IP range 10.0.0.0/16).
Login to your AWS Console and search for VPC on the Dashboard.
Click on VPC and you will be forwarded to the VPC dashboard.
There is already a default VPC present.
However, you must deploy your own bespoke VPC and assign it a name. Within this tutorial I have named mine DemoVpc. Further, you must assign a CIDR range to further limit who can access your network.
As shown in the image below, my Demovpc has been deployed.
Following deployment of a DemoVpc, we will now deploy four subnets underneath it. By default there are also default subnets already present and you can view these:
Public SubnetS (IP range 10.0.0.0/24) – AZ 1a
Within the VPC section, click on the VPC that has just been deployed (I have selected Dmovpc).
Repeat the above step for PublicSubnetB
Public Subnet (IP range 10.0.1.0/24) – AZ 1b
Again, repeat the above step for PrivateSubnetA and PrivateSubnetB.
PrivateSubnetA (IP range 10.0.16.0/20) – AZ 1a
and
PrivateSubnetB (IP range 10.0.32.0/20) – AZ 1b
Further, ensure that auto-assign public IP is set to true for both publicSubnet’s.
This needs to be configured for both public subnets A and B.
Assuming that you already have knowledge of EC2, deploy a new instance within publicSubnetA. Ensure that your instance can be accessed from anywhere (SSH 0.0.0.0./0).
During deployment of your instance, note the following key points:
Within step 3 below, you can deploy an instance using any OS/AMI. In this tutorial I have deployed using Amazon Linux.
Deploy your instance within publicSubnetA using either an existing or new key-pair. This will allow you to later access your instance.
Next, deploy an internet gateway. There is also already a default internet gateway.
To deploy a new internet gateway, click on the option available within the left hand pane.
Deploy a DemoIGW and then associate it with your DemoVPC. This will facilitate communication of traffic between your VPC and the internet.
Attach to VPC
Access the Route Table section:
Deploy two route tables (Public and Private) and associate both with your DemoVpc.
And PrivateRouteTable
Further, associate your public and private subnets with their relevant route tables.
Associate both public subnets with the PubliRoute Table.
Repeat this process for the PrivateRouteTable and associate both of your private subnets with it.
Within the PublicRoute Table, deploy a new route for 0.0.0.0/0 and associate it with your DemoIGW.
Click on Edit routes
Get the free Amazon VPC design checklist
If you are planning your own network’s CIDR, subnets and route tables, then download our one page checklist to aid you in your planning. Complete our quick form to receive a copy of this checklist: [lead form link]
To enable the communication of private instances with the internet we will now deploy a NAT.
Deploy a NAT instance within publicSubnetB. Ensure that it can be accessed from anywhere (SSH 0.0.0.0/0) and that it can communicate with both HTTP and HTTPS traffic (both with IP range 10.0.0.0/16).
Next, deploy a new instance within privateSubnetA. Again, deploy this instance using either an existing or new key-pair. Ensure that it can only be accessed via SSH from within the 10.0.0.0/16 IP range.
Deploy your private instance, again using either an existing or new key-pair.
In order for your NAT to function, ensure that Source/Disable destination check is turned off.
Finally, using your new key, SSH into your private instance from your public instance.
Initially, SSH into your public instance. For this tutorial I am utilising ‘putty’ software and connecting using my public Ec2 instance’s private key.
Within the putty, type in the IPv4 Public IP address of your public Ec2 instance within the Hostname box. You can then log in by typing in either ‘ec2-user’ or your relevant username depending on the OS that you are accessing.
As previously stated, your private instance will not have internet access. Therefore, within your privateRoute table deploy the following:
A route for 0.0.0.0/0 to your NAT instance. Further, within your NAT’s security settings, permit all incoming ICMPV4 traffic.
Navigate to winscp:
To transfer the .pemfile for your private EC2 instance from your local computer to your public EC2 instance, type in the IP address of your public EC2 instance within the Hostname box. Further, within the username box type in your username.
Click on Advanced and then on Authentication. From here, select the private key relating to your public EC2 instance to enable connection to your public EC2 instance using winscp.
Follow the steps demonstrated within the image below:
Finally, terminate your previously deployed NAT instance.
To deploy a NAT Gateway within PublicSubnetA, first terminate your NAT instance.
Deploy NAT Gateway within PublicSubnetA
Deploy NAT Gateway:
Access your PrivateRoute table and amend it so that it routes to your NAT Gateway.
Then, associate your NAT Gateway with your PrivateRouteTable. This will enable your private EC2 instance to communicate with the internet.
To enable DNS public hostname, navigate to your DemoVPC and enable this feature.
Enable
By default, a NACL (Network Access Control List) has also already been deployed for your DemoVPC (DemoNACL).
Both the inbound and outbound settings on this default NACL are permitted.
In this tutorial we will deploy an apache server (Hello World) on our public EC2 instance. To do so, amend the security group settings for your public instance and permit HTTP traffic from 0.0.0.0/0.
Deployment of HTTP server on Public EC2 Instance
Initially, switch to root user:
$ sudo su
Now you will work as superuser or root user
Then update your instance with any latest update (Not mandatory, but keep your instance up to date with latest update)
Now install http server on machine
Click “y”
Once you install it, start the service.
Just to ensure about proper http installation
We also can add an index.html file into the http directory as well.
As shown in the image above, the message “hello world” will be displayed.
Having successfully deployed apache, you can then view it within a browser.
However, if you attempt to do this, and within the NACL amend the inbound settings to deny HTTP (port 80), then your request will not be fulfilled.
Again, if you try to view our page within your browser, your request still will not be fulfilled.
If however, you amend the settings to deny on port 110, then your page will again be viewed. Refreshing your browser will then successfully fulfil your request.
Important: Leave your Network ACL settings unchanged.
VPC Peering
We will establish a peering connection between our default VPC and our DemoVPC.
Further, deploy a new instance within our default VPC. Again, ensure that it can be accessed from anywhere (SSH 0.0.0.0/0). For this tutorial I have deployed an Amazon Linux Instance and have not amended any settings. Therefore, both the VPC and subnet deployed are default ones.
Some key steps are outlined below.
Your default instance within the default VPC is now ready for connection. Using putty, connect to your default VPC instance.
Curl localhost:80 from your public instance. This will successfully occur. However, the same will not be achievable from your default vpc instance.
Establish a peering connection (DemoPeering)
Access the Peering Connections section.
Click on Create Peering Connections
Define yourself as Requestor and your DemoVPC as such.
Define the acceptor as defaultVPC.
Accept the request.
Access your PublicRoute Table and add a rule:
For defaultVPC CIDR to pcx
Repeat this process for the Default RouteTable also.
For DemoVPC(10.0.0.0/16) CIDr to pcx. This will then successfully occur.
And finally, never hesitate to seek assistance!
Amazon VPC enables you to fully manage your AWS network and regulate who can access what. Within this tutorial you have learnt how to deploy a VPC; sub-divide it into public and private subnets; utilise an internet gateway for external internet communication; manage traffic flow using route tables and deploy NAT so that private instances can communicate externally. Moreover, you have seen how to establish a peering connection between two VPCs. Correct initial network design is essential to avoid future re-design. As more workloads continue to move to the cloud, good knowledge of AWS VPC networking will remain highly sought after within AWS related job roles.To build practical AWS networking skills with expert guidance, explore Prwatech’s AWS online training course.
Amazon VPC is a virtually isolated network within the AWS cloud. You can deploy resources onto it. You can define an IP range, establish subnets and manage a network using route tables, gateways and security. Essentially, it functions in a similar way to a physical network within your data centre but on AWS’ scalable infrastructure.
Log into your AWS Console. Search for and open the VPC dashboard. From here, deploy a VPC, assigning it a name and a CIDR range (for example, 10.0.0.0/16). Next, deploy subnets, an internet gateway and route tables so that your network can be utilised.
Public subnets contain a route to an internet gateway. Consequently, instances within them can communicate both with, and from, the internet. Private subnets do not have a direct route to the internet. Instead, instances within them communicate with the internet via a NAT. Further, no external entities can instigate communication with these instances.
It facilitates communication between your VPC and the internet. Firstly, you must deploy an internet gateway and then associate it with your VPC. Finally, you must add a route to 0.0.0.0/0 within your public route table so that it directs traffic to this gateway. Without this, even instances with public IP addresses will not be able to communicate externally.
Route tables are rules that determine where traffic originating from a subnet is directed. Each subnet is associated with one route table. Within this tutorial, the public route table directs internet traffic to our internet gateway whereas the private route table directs it to our NAT.
Whilst private instances do not possess public IP addresses, they frequently require the ability to download updates. Therefore, NAT is utilized to allow these instances to instigate external communication. Furthermore, it prevents external instigation of communication. Both a NAT instance and the managed NAT gateway can be used. Within this tutorial, we initially deploy a NAT instance and then replace this with a NAT gateway.
Within the VPC Peering area, deploy a peering connection. Designate one VPC as Requestor and another as Acceptor. Accept the request. Finally, within each VPC’s route table, add a rule directing traffic for the other VPC’s CIDR range to the peering connection. Communication can then occur between the two VPCs.
Whereas security groups are instance-level, network ACLs (NACLs) are subnet-level. Further, network ACLs contain numbered allow and deny rules which are assessed sequentially. Conversely, security groups only contain allowed rules. Within this tutorial, our web page was prevented from being viewed as a result of the deny rule for HTTP traffic within our NACL. This was rectified by amending this rule.
A NAT instance is an EC2 instance that you manage. You must also ensure that its source/destination check is disabled. In contrast, a NAT gateway is a managed AWS service that is deployed within a public subnet. Within this tutorial, we first deploy a NAT instance to demonstrate its functionality and then substitute it with a NAT gateway.