Can I recover the public IP address or Elastic IP address associated with an EC2 instance, and how can I avoid these being changed in the future?

2 minute read

I stopped and started my Amazon Elastic Compute Cloud (Amazon EC2) instance, and then the public IP address associated with the instance changed. Or, I accidentally released the Elastic IP address associated with my instance.


Public IP addresses

You can't manually associate or disassociate a public IP address from your instance. An instance's public IP address changes in the following scenarios:

  • Stopped or hibernated instances receive a new public IP address when started again.
  • If an instance's associated Elastic IP address is disassociated from the instance, then it receives a new public IP address.

When a public IP address is no longer associated with an instance, that address is returned to the public IP pool. You can't recover the same public IP address for your stopped instance.

Elastic IP addresses

It's a best practice to use an Elastic IP address. Elastic IP addresses are allocated to your account, instead of to the instance. You can associate your Elastic IP addresses to and from instances as needed.

If you released your Elastic IP address, you might be able to recover it. The following rules apply:

  • You cannot recover an Elastic IP address if it has been allocated to another AWS account, or if it will result in your exceeding your Elastic IP address limit.
  • You cannot recover tags associated with an Elastic IP address.
  • You can recover an Elastic IP address using the Amazon EC2 API or a command line tool only.

All instances retain their associated Elastic IP addresses when stopped. AWS continues to bill for Elastic IP addresses associated with a stopped instance.

Note: You can't convert an auto-assigned dynamic public IP address to an Elastic IP address.

For more information, see Recovering an Elastic IP address.

 Recover an Elastic IP address

Use the allocate-address AWS Command Line Interface (AWS CLI) command. specify the IP address using the --address parameter as shown in the following example:

aws ec2 allocate-address --domain vpc --address

Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent version of the AWS CLI.

Related information

Stop and start your instance


AWS OFFICIALUpdated 2 years ago