Public IPs, Private IPs, and Elastic IPs
~10 min read
Three different IP addresses an instance might have, and why they behave differently across a stop/start cycle.
Every EC2 instance in a VPC gets a Private IP address from its subnet's address range, used for communication within the VPC (and, with appropriate routing, to on-premises networks over VPN/Direct Connect) — this private IP typically stays the same for the life of the instance (it doesn't change across a stop/start, only if the instance is terminated and a new one is launched).
An instance in a public subnet can optionally be assigned a Public IP address automatically at launch, which allows direct internet connectivity — but this auto-assigned public IP is NOT persistent: every time you stop and start (not reboot — stop/start) the instance, it gets a new public IP, which breaks anything (DNS records, hardcoded configs) pointing at the old one.
An Elastic IP is a static public IP address you allocate to your account and explicitly associate with an instance — unlike an auto-assigned public IP, it stays the same across stop/start cycles, and you can even move it to a different instance if you need to swap which server is 'live' at that address. The catch: AWS charges for an Elastic IP only when it's NOT attached to a running instance (to discourage hoarding unused static IPs), so an idle allocated-but-unattached Elastic IP quietly costs money while an attached one, in most cases, doesn't.
In the AWS Console
- 1
EC2 → Network & Security → Elastic IPs → Allocate Elastic IP address
Allocate a new Elastic IP, then select it and choose Actions → Associate Elastic IP address, picking your instance.
Remember to release (not just disassociate) an Elastic IP you no longer need — an allocated-but-unattached Elastic IP incurs an hourly charge.
💬 Deep Dive with AI
Key points
- •Private IP: stable within the VPC for the instance's life, used for internal communication
- •Auto-assigned Public IP: changes on every stop/start — never hardcode or point DNS at this
- •Elastic IP: static, persists across stop/start, can be moved between instances, but costs money while unattached
- •For anything needing a stable public address (e.g. a DNS A record), use an Elastic IP, not the auto-assigned public IP