Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the IP address of an amazon EC2 instance on reboot

On reboot, the IP address of an amazon instance changes. How to find the new IP address using java API?

like image 799
figaro Avatar asked Sep 23 '11 07:09

figaro


People also ask

Does rebooting EC2 change IP?

Actually, When you stop/start your instance, the IP address will change. If you reboot the instance, it will keep the same IP addresses. Unfortunately, it is not possible for us to reassign the address to your instance as that address would have been released back into the pool used by other EC2 instances.

What happens when reboot EC2 instance?

When you reboot an instance, it keeps its public DNS name (IPv4), private and public IPv4 address, IPv6 address (if applicable), and any data on its instance store volumes. Rebooting an instance doesn't start a new instance billing period (with a minimum one-minute charge), unlike stopping and starting your instance.


1 Answers

On reboot, the IP addresses of an EC2 instance do not change. They do generally change on stop/start of a non-VPC EBS boot instance.

See my answer to your related question here:

https://stackoverflow.com/questions/7533871/difference-between-rebooting-and-stop-starting-an-amazon-ec2-instance

That said, you can find the private and public IP addresses through the API call for DescribeInstances in your particular language.

If you are on the instance itself, you can also find the IP addresses through the user-data API using simple HTTP:

http://instance-data/latest/meta-data/local-ipv4 http://instance-data/latest/meta-data/public-ipv4 

For example,

wget -qO- http://instance-data/latest/meta-data/public-ipv4 

Elastic IP addresses are recommended for keeping a consistent (static) externally facing IP address for a particular service or server. These need to be re-assigned to an instance after a stop/start (but not after a reboot).

like image 130
Eric Hammond Avatar answered Sep 22 '22 07:09

Eric Hammond