Retain private IP when restoring EC2 instance from AWS Backup or Snapshot

0

Hello all.

I'm testing restores of an EC2 instance and I've found that it never retains the same private IP, regardless of whether it's restored from AWS Backup or an EC2 snapshot.

I've even tried deleting the original instance prior to doing the restore in hopes that the restored EC2 would have the same the private IP as the original (because I know you can't reconfigure the primary private IP of an EC2 or have the same IP on another NIC), but no luck.

It would seem this is a pretty basic functionality and concept, as some servers have hardcoded IPs that can't be changed without wrecking production environments. Am I missing something or is there just absolutely no ability to keep the same private IP when doing a restore?

Please advise.

asked a year ago2241 views
2 Answers
0
Accepted Answer

You can specify the IP Address in a Launch Template, specifically AWS::EC2::Launch Template NetworkInterface

profile pictureAWS
answered a year ago
profile pictureAWS
EXPERT
reviewed a year ago
0

It's good to avoid the issue using domain names or internal load balancers, but there are some ways of getting the same private IP.

One is to use an additional ENI that you attach to your instance in addition to the default ENI. Other resources can reference the private IP of this additional ENI, which can be detached and attached to another instance as needed. Note it needs to be in the same AZ but different subnet than the default ENI.

Another hack I've heard of is using a very small subnet (/28) and using up all but one of the available IP addresses. Then when your instance starts it's forced to always use the same IP address.

EXPERT
answered a year ago
  • Thanks for adding the much better answer @Rodney Lester. My info was way out of date - somehow in the shift from Launch Configurations to Launch Templates years ago I never noticed (or have forgotten) that specifying a primary IPv4 address is now possible. Cheers.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions