Ec2 instance static private ip address

amazon ec2amazon-vpcamazon-web-servicesprivate-ip

I am using an on-demand instance for testing some services in my spare time.

So, I start and stop that instance very frequently, and I see its public and private IPs changing each time. This is annoying, because I always need to change hostname in several applications using test services.

What I want is to have at least a "fixed", static private IP.

I read somewhere that adding ENI interface could be the solution. In this case, can you provide me a simple example on how to do that?

In other case, what's the cleaner solution?

Best Answer

You tagged this , but the behavior you describe is what happens when an instance is launched in EC2-Classic. When you launch an instance in a VPC, it is assigned a private IP address and it remains for the lifetime of the instance. Their documentation is pretty clear on that point. To be clear, 'instance' in this case is a discrete 'i-' number.

EC2-Classic has no support for what you're looking for, and you can't assign new interfaces to it.

If you're not actually keeping the same instance defined and are spinning a new one up in a VPC based off of an AMI you have, you will get a new private IP address each time. As you suspected, if you define a new Interface and associate it with the instance, that Interface will have a static IP address. When you terminate the instance, the extra Interface goes unassigned. Reassign it to a new instance when you spin one up.