Skip to main content

βš™οΈ 05. EC2 Network Settings

EC2 Network Settings allow you to configure networking components such as VPC, Subnets, Security Groups, and Public IP Addresses during instance creation.


🌐 VPC (Virtual Private Cloud)​

  • A VPC is a logically isolated section of the AWS Cloud where you can launch AWS resources.
  • It lets you define:
    • IP address ranges
    • Subnets
    • Route tables
    • Gateways (Internet or NAT)
  • You can use the default VPC or create a custom VPC for more granular control.
  • Each VPC spans a single AWS Region and can have multiple subnets across different Availability Zones.

🧩 Subnet​

  • A Subnet is a segment of a VPC’s IP address range where you can place your resources.
  • Subnets help divide your network into smaller, manageable sections.
  • Each subnet must reside in a single Availability Zone.
  • Types of subnets:
    • Public Subnet – Connected to the Internet through an Internet Gateway.
    • Private Subnet – Isolated from the Internet, often used for databases or internal apps.
  • You can create multiple subnets in your VPC for better fault tolerance and organization.

πŸ”’ Security Groups​

Security Groups are the foundation of network security in AWS. They act as virtual firewalls that control how traffic is allowed into or out of your EC2 instances.

βš™οΈ Key Features​

  • Security groups contain rules only inbound traffic is denied by default and outbound traffic are authorised by deafult
  • Rules can reference:
    • IP addresses (IPv4 or IPv6)
    • Other security groups
  • They manage:
    • Inbound traffic β†’ from external sources to the instance
    • Outbound traffic β†’ from the instance to external destinations

Security Groups operate at the instance level and act as a firewall that regulates:

  • Access to specific ports
  • Authorized IP ranges (IPv4 / IPv6)

🌍 Common Ports to Know​

PortProtocolDescription
22SSHLog into a Linux instance
21FTPUpload files to a file share
22SFTPUpload files securely using SSH
80HTTPAccess unsecured websites
443HTTPSAccess secured websites
3389RDPLog into a Windows instance

πŸ’‘ Tip: By default, all inbound traffic is blocked, and all outbound traffic is allowed β€” you must explicitly allow inbound connections (like SSH or HTTP).


🧩 Security Groups β€” Good to Know​

  • πŸ” Can be attached to multiple instances
    A single security group can secure multiple EC2 instances.

  • 🌍 Locked to a Region / VPC
    Security groups are specific to a Region and VPC β€” they can’t be reused across regions.

  • 🧱 Exist outside the EC2 instance
    Security groups filter traffic before it reaches the instance.
    If traffic is blocked, the instance never sees it.

  • 🧰 Best Practice:
    Maintain a separate security group for SSH access to simplify management and auditing.


πŸ”— Referencing Other Security Groups​

In AWS, Security Groups can reference other Security Groups instead of using IP addresses. This allows secure communication between specific EC2 instances or tiers (like web ↔ app ↔ database) within your VPC.


🧠 How It Works​

  • Instead of allowing access from a public IP (like 0.0.0.0/0),
    you can specify another Security Group as the source or destination in your rule.
  • This means only instances that belong to that referenced Security Group can communicate.

πŸ’‘ Example Use Case​

LayerSecurity GroupPurposeAllows Traffic From
Web TierSG-WebHosts public web servers0.0.0.0/0 (Internet)
App TierSG-AppRuns backend application serversSG-Web
DB TierSG-DBHosts databasesSG-App

➑️ Here,

  • Web servers can reach App servers,
  • App servers can reach Databases,
  • But Web servers cannot directly reach Databases.

🧩 Benefits​

  • πŸ›‘οΈ Enhanced security β€” avoids exposing internal layers to the internet.
  • πŸ”„ Dynamic β€” if new instances join the referenced group, rules automatically apply.
  • 🧰 Simplifies management β€” no need to update IPs when instances change.

πŸ’¬ Example Rule:
Allow inbound traffic on port 3306 (MySQL) from security group SG-App.
This means only EC2 instances in SG-App can connect to the database instance.


🚨 Troubleshooting Tips​

ProblemLikely Cause
Application times outSecurity group blocking incoming traffic
Application shows "connection refused"Application not running or internal app error