- Newest
- Most votes
- Most comments
Thank you for reporting this issue. What you've experienced is not a bug, but rather the expected behavior for EC2 instances with public IP addresses.
When an EC2 instance is stopped and then started again, it does not retain its previously assigned public IP address. This is by design for instances using auto-assigned public IP addresses. The public IP address is released back into Amazon's pool of public IPv4 addresses when the instance is stopped, and a new one is assigned when the instance is started again.
This behavior applies to auto-assigned public IP addresses, not Elastic IP addresses. If you need a consistent public IP address that persists across instance stops and starts, you should consider using an Elastic IP address instead. Elastic IP addresses remain associated with your AWS account until you choose to release them, and they can be easily reassigned to instances as needed.
For your use case, where you need consistent public IP addresses across multiple servers that may be stopped and started, using Elastic IP addresses would be the recommended approach. This would eliminate the need for the workaround you described and provide a more stable and manageable solution for your infrastructure.
If you're using CloudFormation to manage your resources, you can include Elastic IP allocation and association in your stack template. This way, your instances will always have the same public IP address, regardless of stop/start cycles.
Sources
After stop and start, we are loosing public IP of EC2 | AWS re:Post
Amazon EC2 instance IP addressing - Amazon Elastic Compute Cloud
If you don't care what public IP get assigned but just want to ensure there is one, then enable automatic public IP association on the subnet.
Relevant content
- asked 9 months ago
- asked a year ago
- AWS OFFICIALUpdated 4 years ago
