Skip to main content

Command Palette

Search for a command to run...

AWS EC2 Security Groups and Elastic IPs

Updated
2 min read

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

  1. Launched a t2.micro Ubuntu EC2 instance.

  2. Created a custom security group with:

    • SSH: My IP only.

    • HTTP: Open to all.

  3. Connected using SSH via terminal.

  4. Installed Apache and tested with a browser.

  5. Allocated and attached an Elastic IP.

  6. 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:


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.

More from this blog

Documenting My DevOps Journey

40 posts