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
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Public IP addresses
When a public IP address is no longer associated with an instance, that address returns to the public IP address pool. You can't recover the same public IP address for your stopped instance. The new automatically assigned public IP address is randomly picked from the public IP address pool.
An instance's public IP address changes in the following scenarios:
- Amazon EC2 gives a new public IP address to stopped or hibernated instances when they start again.
- You disassociated an instance's associated Elastic IP address from the instance, so the instance received a new public IP address.
- You unassigned a public IP address, and then assigned a new public IP address in the primary network interface settings.
Elastic IP addresses
It's a best practice to use an Elastic IP address instead of a public IP address. This is because AWS allocates Elastic IP addresses to your AWS account instead of to the instance. Then, you can associate your Elastic IP addresses to and from instances. When you stop an instance, it retains its associated Elastic IP addresses. AWS continues to bill Elastic IP addresses associated with a stopped instance.
To recover an Elastic IP address, you must use the Amazon EC2 API or a command line tool. You can't recover an Elastic IP address that's allocated to another account, or if you reached the quota for the maximum number of Elastic IP addresses.
Note: You can't recover tags associated with an Elastic IP address. You also can't convert an auto-assigned dynamic public IP address to an Elastic IP address.
To recover an Elastic IP address, run the following allocate-address AWS CLI command:
aws ec2 allocate-address --domain vpc --address 000.0.000.0
Note: Replace 000.0.000.0 with your Elastic IP address.
Related information
AllocateAddress