6

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?

2 Answers 2

8

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.

1

Create a network interface. Assign the IP address(es) you want to use. After launching an instance you want to use these addresses, select that network interface and click "Attach". In the pop-up dialog, the drop-down "Select Instance" has a list of your running instance that were running when you came to the network interface page. If the instance is not in the list, be sure it is running and reload the network interface page and try again. Click on "Attach" in the dialog. That instance will then be operating with that interface. It should not need a reboot.

When the instance is terminated the attached interface will be available, again, for other use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .