While working with Amazon EC2, I noticed something interesting about public IP addresses.
I launched an EC2 instance and checked its public IP:
Public IP: 13.x.x.x
Then I stopped the instance and started it again.
After restarting, I noticed that the public IP had changed:
Old IP: 13.x.x.x
New IP: 54.x.x.x
This made me understand an important AWS concept:
The default public IPv4 address of an EC2 instance is not persistent.
🔹 So, how can we keep the same public IP?
AWS provides Elastic IP, which is a static public IPv4 address.
I allocated an Elastic IP and associated it with my running EC2 instance.
After that, I stopped the instance and started it again.
This time:
Before Stop: 3.x.x.x
After Start: 3.x.x.x ✅
The IP remained the same.
Architecture
AWS
|
Elastic IP
3.x.x.x
|
▼
EC2 Instance
┌─────────────┐
│ Web Server │
└─────────────┘
🔹 What did I learn?
The key difference is:
Default Public IP
Automatically assigned by AWS
Can change when an EC2 instance is stopped and started
Not suitable when a fixed public IP is required
Elastic IP
Static public IPv4 address
Can be associated with an EC2 instance
Remains the same even after stop/start
Can also be disassociated and associated with another resource when required
🔹 How is it used in real-world environments?
Elastic IPs are useful when a service needs a predictable public IP.
For example:
IP whitelisting for external APIs
Bastion/Jump hosts
NAT Gateway for fixed outbound IP
Applications where a fixed public IP is specifically required
However, in a production architecture using Application Load Balancer + Auto Scaling, we generally don't assign an Elastic IP to every EC2 instance.
Instead:
Internet
|
▼
Application Load Balancer
|
┌──────┴──────┐
▼ ▼
EC2-1 EC2-2
│ │
└──────┬──────┘
▼
Auto Scaling
The Load Balancer provides the stable entry point, while EC2 instances can scale in and out behind it.
💡 My Key Takeaway
This hands-on experiment helped me understand why AWS provides different types of IP addressing and when a static public IP is actually required.
Need a fixed public IP → Elastic IP
Need scalable public access → Load Balancer
Need fixed outbound IP for private resources → NAT Gateway + Elastic IP
Learning AWS concepts becomes much clearer when you actually test them instead of only reading about them.
Top comments (0)