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.

preguntada hace un año2318 visualizaciones
2 Respuestas
0
Respuesta aceptada

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

profile pictureAWS
respondido hace un año
profile pictureAWS
EXPERTO
revisado hace un año
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.

EXPERTO
respondido hace un año
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas