AWS Security Group Exercise to help you understand how to create, configure, and manage security groups in AWS:
You will:
- Create a security group with custom inbound and outbound rules.
- Attach the security group to an EC2 instance.
- Test the security group configuration.
- Modify rules to demonstrate their impact.
- An AWS account.
- Access to the AWS Management Console or AWS CLI.
- A running EC2 instance or ability to launch one.
- Login: Sign in to the AWS Management Console.
- Navigate: Go to the EC2 Dashboard.
- Select Security Groups:
- In the left-hand menu, under "Network & Security," click Security Groups.
- Click Create Security Group.
- Configure Security Group:
- Name:
MySecurityGroup - Description: "Security group for testing inbound and outbound rules."
- VPC: Select the default VPC or the VPC where your resources reside.
- Name:
- Add Inbound Rules:
- Rule 1: SSH (port 22), Source: Your IP (for SSH access).
- Rule 2: HTTP (port 80), Source: Anywhere (0.0.0.0/0).
- Add Outbound Rules:
- Leave default rules to allow all outbound traffic.
- Create:
- Click Create Security Group.
- Navigate to EC2 Instances:
- Select an existing EC2 instance or launch a new one.
- Edit Security Groups:
- Select the instance and click Actions > Security > Change Security Groups.
- Attach the
MySecurityGroupto the instance.
- Verify:
- Ensure the security group is listed under the instance's Security tab.
- Test SSH Access:
- Use the following command to SSH into the instance:
ssh -i <your-key-pair.pem> ec2-user@<instance-public-ip>
- Verify successful access.
- Use the following command to SSH into the instance:
- Test HTTP Access:
- If you have a web server running on the instance, access it via a browser:
http://<instance-public-ip> - Verify access to the web server (e.g., Apache default page or your custom page).
- If you have a web server running on the instance, access it via a browser:
- Restrict SSH Access:
- In the Security Group settings, edit the Inbound Rules and change the Source of the SSH rule to a specific IP range (e.g.,
192.168.0.0/24). - Try connecting via SSH from an unauthorized IP.
- In the Security Group settings, edit the Inbound Rules and change the Source of the SSH rule to a specific IP range (e.g.,
- Block HTTP Traffic:
- Remove the HTTP (port 80) rule.
- Test web server access again; it should fail.
- Detach Security Group:
- Go to the EC2 instance, and replace
MySecurityGroupwith the default security group.
- Go to the EC2 instance, and replace
- Delete Security Group:
- In the Security Groups menu, select
MySecurityGroupand click Delete.
- In the Security Groups menu, select