-1

I take create an AMI image from a Linux running instance [ centos ]. It has only private IP. Some of the random instance while restoring in a different VPC, retains the old IP or we just couldn't reach it.

Source AMI server has:

[centos@ip-xxxx ~]$ cat /etc/sysconfig/network
# Created by cloud-init on instance boot automatically, do not edit.
#
NETWORKING=yes

[centos@ip-xxxx ~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

[centos@ip-xxxx ~]$ cat /etc/resolv.conf
; generated by /usr/sbin/dhclient-script
search ec2.internal
nameserver xxxx

Has anyone faced this? Why is it happening? I couldn't find any pattern. Similar servers from same VPC when I restore the AMI, some works, some doesn't randomnly. Its so confusing! Any help appreciated. Thanks.

1 Answers1

0

An Amazon EC2 instance should not be hard-coding its IP address.

Rather, the private IP address is allocated to the instance via DHCP. The VPC will always serve the same private IP address to an instance (similar to having a DHCP reservation). However, a new instance launched from the same AMI is not considered to be the same instance, so it will receive a 'new' private IP address via DHCP. (It could be the same IP address if both subnets have the same CIDR range, but it is unlikely.)

If you are seeing an incorrect IP address associated with an instance, it is likely because somebody hard-coded it into a configuration file (which is not a good idea).

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • May be it's not the IP. Instance screenshot showed old IP. However other instances came up with new IP even though instance screenshot was misleading. For some reason, the AMI snapshots restored to an EC2 ends up with status check failed . Virtualization type is same too. It was bit confusing. Thanks for your time. – Chakaravarthy Natesan Mar 21 '20 at 05:07