Skip to content

Issue with automatic public IP adress (Bug report)

0

Recently I have launched an ec2 instance through a cloudformation stack, without automatic public IP enabled. I then added automatic public IP to the running instance to one of the eni's and it got assigned. After I was done I shut down the instance and when I restarted it, no public IP got assigned.

I managed to get a workaround by disabling the automatic IP for the eni, logging out of the console and then logging back in and reactivating the public IP setting. Surely this must be a bug, as this is ok for one instance but it would be really annoying doing this for multiple servers.

2 Answers
2

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

answered a year ago
AWS
EXPERT
reviewed a year ago
EXPERT
reviewed a year ago
0

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.

AWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.