How do I recover the public IP address or Elastic IP address associated with an EC2 instance?

3 minute read
0

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.

Resolution

Public IP addresses

You can change or unassign a public IP address of your EC2 instance after launch by managing the IP addresses associated with a network interface.

To assign or unassign a public IPv4 address to a network interface after launch, choose Auto-assign public IP in the primary network interface settings. You can activate or deactivate this option for any network interface but the setting applies only to the primary network interface (eth0).

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 the instance receives a new public IP address.
  • You unassign and then assign a public IP address in the primary network interface settings.

When a public IP address is no longer associated with an instance, that address returns to the public IP address pool and can't be recovered. You can't recover the same public IP address for your stopped instance. The new auto-assigned public IP address is random.

Elastic IP addresses

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

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

  • You can't recover an Elastic IP address if it's allocated to another AWS account.
  • You can't recover an Elastic IP address if you already reached the limit for the number of Elastic IP addresses that you can have.
  • You can't recover tags associated with an Elastic IP address.
  • You can use only the Amazon EC2 API or a command line tool to recover an Elastic IP address.

All instances retain their associated Elastic IP addresses when they are 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.

Recover an Elastic IP address
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you're using the most recent AWS CLI version.

Use the allocate-address AWS CLI command. Specify the IP address using the --address parameter as shown in the following example:

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

Related information

Stop and start Amazon EC2 instances

AllocateAddress

Manage the IP addresses for your network interface

AWS OFFICIAL
AWS OFFICIALUpdated 6 days ago