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

前端 未结 10 1332
长发绾君心
长发绾君心 2020-12-12 13:50

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

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-12 14:00

    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).

提交回复
热议问题