How to Set Up a Firewall in AWS: A Step-by-Step Guide

When securing your AWS environment, you have two primary firewall layers: Security Groups (stateful, instance-level) and Network ACLs (stateless, subnet-level). Both control inbound and outbound traffic, but they operate differently. This guide walks you through setting up each one to protect your cloud resources.

Security Groups act as a virtual firewall for EC2 instances, allowing only the traffic you explicitly define. They are stateful, meaning return traffic is automatically permitted. Network ACLs, on the other hand, are stateless and apply to entire subnets. You must define rules for both inbound and outbound traffic separately. Let’s dive into the configuration steps.

Article illustration

Setting Up a Security Group

  1. Navigate to the EC2 console and select Security Groups under Network & Security.
  2. Click Create Security Group. Give it a descriptive name and select the VPC.
  3. Add inbound rules: specify the protocol (e.g., TCP), port range (e.g., 22 for SSH), and source (e.g., your IP).
  4. Add outbound rules if needed. By default, all outbound traffic is allowed.
  5. Attach the Security Group to your EC2 instances during launch or later via the instance’s Networking tab.

Configuring a Network ACL

  1. In the VPC console, go to Network ACLs and click Create Network ACL.
  2. Associate it with a subnet in your VPC.
  3. Edit inbound rules: add rules with a Rule Number (lower numbers evaluated first), Type (e.g., HTTP), Protocol, Port Range, Source (CIDR block), and Action (Allow/Deny).
  4. Edit outbound rules similarly. Remember that NACLs are stateless—you must allow reply traffic explicitly (e.g., allow ephemeral ports outbound).
  5. To enforce “deny all” by default, ensure the last rule (deny all traffic) remains in place.

Firewall Best Practices

  • Use Security Groups for granular per-instance control; use NACLs as an additional security layer for subnets.
  • Follow the principle of least privilege—only open the specific ports and sources required.
  • Regularly audit rules using AWS Config or Security Hub.
  • Remember: Security Group rules have an implicit deny; NACLs require explicit deny rules for blocking traffic.

By combining Security Groups and Network ACLs, you create a robust defence for your AWS infrastructure. Start with the basic setup outlined above, then refine as your security needs evolve.

sarah antaboga
Author: sarah antaboga

Leave a Reply

Your email address will not be published. Required fields are marked *