Security groups and Network ACLs are similar in that they allow you to control access to AWS resources within your VPC. Howerver, SGs allow you to control inbound and outbound traffic at the instance level, while NACLs offer similar capabilities at the VPC subnet level.
Aim
To provide a comprehensive, step-by-step guide understanding on how to configure and manage key components such as VPCs, subnets, internet gateways, route tables, security groups, and Network ACLs, ensuring a secure and scalable environment for deploying AWS resources.
Objective
- Demonstrate the creation and configuration of a VPC and its associated components, including public and private subnets.
- Illustrate the setup and association of Security Groups and Network ACLs to control inbound and outbound traffic at both the instance and subnet levels.
- Guide readers through the process of launching and securely accessing an EC2 instance within the configured VPC environment.
Steps
1. Create a VPC
- Log in to the AWS Management Console.
- Navigate to the VPC Dashboard.
- Click on Your VPCs in the left-hand menu.
- Click on Create VPC.
- Enter the following details:
Name tag:
MyVpc
IPv4 CIDR block:10.0.0.0/16
IPv6 CIDR block: No IPv6 CIDR Block Tenancy: Default - Click on Create VPC.
2. Create Subnets
- Create Public Subnet
- In the VPC Dashboard, click on Subnets.
- Click on Create subnet.
- Enter the following details:
Name tag:
PublicSubnet
, VPC: SelectMyVpc
, Availability Zone: Choose one (e.g.,af-south-1a
), IPv4 CIDR block:10.0.1.0/24
. - Click on Create subnet.
Create Private Subnet
- In the VPC Dashboard, click on Subnets.
- Click on Create subnet again.
- Enter the following details:
Name tag:
PrivateSubnet
VPC: SelectMyVpc
Availability Zone: Choose one (e.g.,af-south-1b
) IPv4 CIDR block:10.0.2.0/24
- Click on Create subnet.
3. Create an Internet Gateway
- Click on Create internet gateway.
- Enter the following details:Name tag:
MyInternetGateway
- Click on Create internet gateway.
- Select the newly created internet gateway, then click on*Actions* and select Attach to VPC.
- Choose
MyVpc
and click on Attach internet gateway.
4. Create Route Tables
Create Public Route Table
- In the VPC Dashboard, click on Route Tables.
- Click on Create route table.
- Enter the following details:
Name tag:
PublicRouteTable
VPC: SelectMyVpc
- Click on Create route table.
- Select the newly created route table, click on Routes, then click on Edit routes.
- Add the following route:
Destination:
0.0.0.0/0
Target: SelectInternet Gateway
and then selectMyInternetGateway
- Click on Save routes.
- Click on the Subnet associations tab, then click on Edit subnet associations.
- Select
PublicSubnet
and click on Save associations.
Create Private Route Table
- Click on Create route table again.
- Enter the following details:
Name tag:
PrivateRouteTable
VPC: SelectMyVpc
- Click on Create route table.
- No need to add routes for the private route table at this point unless you have a specific setup (e.g., NAT Gateway for internet access)
- Click on the Subnet associations tab, then click on Edit subnet associations.
Select
PrivateSubnet
and click on Save associations.
5. Create Security Groups
Create Public Security Group
- In the EC2 Dashboard, click on Security Groups.
- Click on Create security group.
- Enter the following details:
Name tag:
PublicSG
Description: Security group for public instances VPC: SelectMyVpc
- Add Inbound Rules:
Type:
SSH
Protocol:TCP
Port Range:22
Source:0.0.0.0/0
(Allow access from anywhere) - Add Outbound Rules: The default outbound rule allows all traffic.
- Click on Create security group
6. Create Network ACLs
Create Public Network ACL
- In the VPC Dashboard, click on Network ACLs.
- Click on Create network ACL.
- Enter the following details:
Name tag:
PublicNACL
VPC: SelectMyVpc
- Click on Create network ACL.
- Add Inbound Rules:
Rule #:
100
Type:SSH
Protocol:TCP
Port Range:22
Source:0.0.0.0/0
(Allow access from anywhere) - Add Outbound Rules:
Rule #:
101
Type:Custom TCP
Protocol:TCP
Port Range:1024-65535
Destination:0.0.0.0/0
Associate with Subnet:
- Select the Subnet: Choose the
public subnet
to associate with this NACL. - Click on Save.
Create Private Network ACL
- In the VPC Dashboard, click on Network ACLs.
- Click on Create network ACL.
- Enter the following details:
Name tag:
PrivateNACL
VPC: SelectMyVpc
- Click on Create network ACL.
- Add Inbound Rules:
Rule #:
100
Type:SSH
Protocol:TCP
Port Range:22
Source:0.0.0.0/0
(Allow access from anywhere)Rule #:
101
Type:Custom TCP
Protocol:TCP
Port Range:1024-65535
Source:0.0.0.0/0
(Allow access from anywhere)
Associate with Subnet:
- Select the Subnet: Choose the
private subnet
to associate with this NACL. - Click on Save.
7. Create Ec2 Instance
- Click on Launch Instance.
- Enter the following details:
Name:
PublicServer
AMI: Choose an Amazon Linux 2 AMI (HVM), SSD Volume Type Instance Type: t2.micro (or another type as needed) Key Pair: Select an existing key pair or create a new one Network: SelectMyVpc
Subnet: SelectPublicSubnet
Auto-assign Public IP: Enable Security Group: SelectPublicSG
- Click on Launch Instance
8. Connect to an EC2 Instance Using EC2 Instance Connect
- Navigate to the EC2 Dashboard.
- Select the
PublicServer
Instance. - Click on Connect at the top of the page.
- Choose EC2 Instance Connect as the connection method.
- Click on Connect to open the terminal.
Conclusion
Security Groups (SGs) and Network ACLs (NACLs) are essential for controlling access to AWS resources within a VPC. SGs manage traffic at the instance level with stateful filtering, while NACLs provide stateless filtering at the subnet level. Together, they offer a robust security framework, ensuring both individual instance protection and broader network security within your VPC. This layered approach enhances the overall security and resilience of your AWS environment.
Top comments (0)