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.

質問済み 1年前2320ビュー
2回答
0
承認された回答

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

profile pictureAWS
回答済み 1年前
profile pictureAWS
エキスパート
レビュー済み 1年前
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.

エキスパート
回答済み 1年前
  • 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.

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ