Question

I'm running an ubuntu AMI on EC2. Is it possible to assign/request a new public IP address for a running EC2 instance without terminating it and starting it again? Note that I'm not interested in using the Elastic IP feature here, I just want to use the regular random public IP addresses assigned by EC2.

Was it helpful?

Solution

Update
As Alex B points out in the comments, AWS EC2 instances now have per-second billing, with a minimum billing period of 1 minute. That's a huge, and welcome improvement. It means that starting and stopping an instance should refresh the IP without racking up extra costs.

The one important thing to keep in mind is that per-second billing only applies to Amazon Linux and Ubuntu instances. Other OSs are billed hourly as before. In those cases, the original method explained below is likely the best option.


Stopping and starting an instance is one way to change your IP, but it isn't the fastest or even the cheapest, however it does meet your criteria of avoiding Elastic IPs.

Stopping and starting an instance, from a billing perspective is the same as terminating/relaunching an instance.

Pricing is per instance-hour consumed for each instance, from the time an instance is launched until it is terminated or stopped. Each partial instance-hour consumed will be billed as a full hour. http://aws.amazon.com/ec2/pricing/

This means that, if you start an instance, stop it half an hour later, then start it again and run it for half an hour then stop it again, for that one hour, you're actually going to be billed for two hours of usage.

Elastic IPs are very likely a better solution in that scenario, but the added cost of Elastic IPs is something most people want to avoid. We don't actually want a fixed IP. We just want a new one. Paying for unique IPs per instance doesn't make sense for this. The interesting thing is, we don't need an EIP for each instance in order to release/renew the instance's external IP. We just need one for the entire VPC.

When you assign an EIP to an instance, the old IP is completely gone, released into the void. When you remove the EIP from the instance, the instance is then forced to request a new external IP from the pool.

Keeping a single Elastic IP attached to an instance in the Oregon region (us-west-2) is free, as long as it's attached to something. If it's not attached, it costs $0.05/hour to sit there.

The first 100 IP remaps each month are free. To us, that works out to 50 free IP refreshes (1 remap for release, 1 for renew). If you break that 100 remap limit, the price jumps quickly, to $0.10/remap (or $0.20/IP refresh), so try to keep track. http://aws.amazon.com/ec2/pricing/

TL;DR

The free EIP powered solution? A single EIP for your entire VPC, assigned to a single instance. When you want to release/renew, transfer that IP to the instance in need of a new IP, then transfer it back to the original instance. You can now quickly change an instance's IP up to 50 times a month at no extra cost.

The IP shuffle, ladies and gentlemen :)

OTHER TIPS

Reboot does not change your IP

If you reboot your instance from within the EC2 Ubuntu machine, e.g. typing

$ reboot

then your instance will keep the same internal and public IP.

Stopping the instance does change your IP

If you use your AWS EC2 management console and stop your machine (don't terminate it!), you give up the assigned IP addresses.

stopping ec2 instance

You will request a new address if you start the instance again.

How to quickly check your IP

You can check for your public and private IPs using CURL or Perl GET, install

$ sudo apt-get install libwww-perl

Now type for internal:

$ GET http://169.254.169.254/latest/meta-data/local-ipv4; echo
172.31.44.114

Or for public:

$ GET http://169.254.169.254/latest/meta-data/public-ipv4; echo
54.72.253.107

Read more.

You cannot have the public IP assigned to an instance once it is created. Doesn't matter whether it is stopped or running.

Your only option is Elastic IP.

And the public IP can only be assigned to an instance at the time of its creation. Once it is created, your are out of luck.

Double Remap

Elastic IP double- remap will change public IP.

  • Take instance without Elastic IP.
  • Associate Elastic IP with this instance
  • Release Elastic IP from This instance

Voila! Public IP changed with only sub-second use of Elastic IP.

Disadvantages

You can do Elastic IP remap only 100 times/month without charge ($0.1/remap afterwards)

The only other option that you might have is to stop and start the instance and it is possible that the public IP would be changed. I am not asking you to terminate the instance. Just stop the instance and then re-start it. It will assign (most likely) a new public IP to your instance.

For those who have down voted without knowing things, please find the link below that tells what I have saying. Read This

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top