AWS EC2 Security Groups and Elastic IPs
Concepts Covered
1. Security Groups – The AWS Firewall
Security Groups act as virtual firewalls for your EC2 instances. Today, I manually configured inbound and outbound rules for different use cases:
Allowed SSH (port 22) only from my personal IP – instead of
0.0.0.0/0, which I had used earlier (😬 bad practice).Allowed HTTP (port 80) access from anywhere (
0.0.0.0/0) since I want the public to access my deployed web server.Outbound rules were kept open (default), but noted how we can restrict them for more secure applications.
Troubleshoot Moment:
Initially, I couldn’t SSH into the instance even after configuring the key pair correctly. After double-checking, I realized my local IP had changed (thanks to switching networks), so I updated the security group’s SSH rule with the new IP.
2. Elastic IP – Making Public Access Persistent
Every time an EC2 instance is stopped and restarted, its public IPv4 address changes unless an Elastic IP (EIP) is attached.
To solve this:
Allocated an Elastic IP from the AWS Console.
Associated it with my running EC2 instance.
Now, I can consistently access the instance even after reboots.
Lesson: Always use Elastic IPs for resources that need persistent public access (especially in demo or production environments).
What I Did – Step-by-Step
Launched a t2.micro Ubuntu EC2 instance.
Created a custom security group with:
SSH: My IP only.
HTTP: Open to all.
Connected using SSH via terminal.
Installed Apache and tested with a browser.
Allocated and attached an Elastic IP.
Rebooted the instance to verify that the IP remained the same.
Security Note
Avoid keeping port 22 (SSH) open to all IPs (0.0.0.0/0). It’s a major security risk. Use:
Your specific IP (get it from
https://whatismyipaddress.com/)Or better: Set up a bastion host (future topic).
Final Thoughts
Today’s session reminded me how basic networking and access control can either secure or expose your entire cloud environment. It’s not about clicking launch on EC2 — it’s about launching it responsibly.