How do I persist a hostname or IP to my Amazon EC2 Instance?

Michael Haren asked:

Suppose I spin up a machine in EC2. Every time I stop/start the machine the following things change (reboots are safe–they don’t cause these to change):

  • public IP address
  • public DNS record
  • private IP address
  • private DNS record
  • removes associated elastic IP

How can I reliably connect to the machine if the addresses/DNS records change every time it is started?

Should I stick with EIPs but add a startup script to reassociate it with my instance when it boots?

There’s got to be a better way!

My answer:


If you stop an instance in EC2, then any associated Elastic IPs are disassociated, and you must reassociate them yourself. However, the same doesn’t apply to instances in VPC; in this case the Elastic IP remains associated, even when the instance is stopped.

See the Elastic IP Address documentation for further details.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.