EC2 instance doesn't get a new public IP after Elastic IP is disassociated

0

I recently had a need to attach an Elastic IP to an instance that previously had a Public IP - got tired of changing SSH keys whenever I rebooted as I was assigning the same private IP to the instance. However, the need for a static IP across reboots has now waned and I wanted to revert to the Public IP setting. However, after detaching the Elastic IP, the instance did not get another Public IP as stated in this document:

https://aws.amazon.com/premiumsupport/knowledge-center/ec2-recover-ip-address/

Instead, I had to resort to creating an AMI and launching a new instance with a Public IP. Is this now the only way to get a Public IP after an Elastic IP is detached?

ak2766
asked 2 years ago2522 views
5 Answers
0

The reason why you can't get the public IP address when you detach the EIP you asked for the first time is also because the secondary ENI is attached.

And we will advise you on your additional questions.

I understand that you are attaching and detaching Elastic IP between nodes to achieve floating IP.

You can build a Network load Balancer for inbound and outbound to communicate by installing a NAT gateway in each AZ from the private subnet.

Or, if you just want to operate the AWS CLI while keeping the current configuration, how about using the VPC endpoint to operate the Elastic IP with private communication?

profile picture
EXPERT
iwasa
answered 2 years ago
  • Thanks @iwasa. I'm new to load balancers on AWS so I'm going to have to go read about them before I proceed. Need to get a full understanding before I start migration of production workloads.

    I'll post back once my understanding is clear; will most likely accept this as the answer.

0

Hi, @ak2766

Detaching an Elastic IP address usually assigns it a public IP address.
Isn't it assigned even if stop → start?

In that case, you may have multiple ENIs attached to your EC2. In that case, the public IP address will not be automatically assigned when the Elastic IP address is detached.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html#concepts-public-addresses

If the public IP address of your instance in a VPC has been released, it will not receive a new one if there is more than one network interface attached to your instance.

You should detach the non-primary ENI once, stop EC2 and then start. You should be assigned a public IP address.

Then reattach the detached secondary ENI.

profile picture
EXPERT
iwasa
answered 2 years ago
0

Thanks for all your answers and I see I'm in a bit of a quandary.

I'm in the process of setting up a highly available NFS cluster using BRDB across AZ's and hence need secondary interfaces as well as Elastic IP's. I was intending on making use of the OCF Heartbeat RA's - namely awseip and awsvip. The problem occurs when the floating IP is moved to another node. When that happens, the node can no longer reach the AWS API via AWSCLI since there's no longer an IP address that can reach the Internet. Currently, I'm forced to do it all in the same node AZ but that means if the AZ is down, then so too is that "highly (un)available" NFS cluster.

Out of the box thinking will be required here.

ak2766
answered 2 years ago
0

You can setup instance with 2 Network Interfaces. The primary network interface (eth0) would have a Public IP which would remain the same for the life of the instance. The secondary interface would have the Elastic IP which could be the floating IP you need. When the Elastic IP get reassigned to the other node due to the failover or any other underlying reason as configured, the instance wont lose access to the internet since the Public IP stays the same.

Why not try Amazon EFS? It would save you the overhead of managing NFS cluster. (Unless you have already done so and have overwhelming reason not to use EFS )

--Syd

profile picture
Syd
answered 2 years ago
0

Unfortunately, only way to get a Public IP after an Elastic IP is detached (for EC2 that disable public IP) is to recreate EC2.

It seems that initially, you had an EC2 instance without a public IP. Later, you attached an Elastic IP (EIP) to the instance to give it a static IP address. Now, if you have disabled the option to auto-assign public IP addresses when launching EC2 instances and you detach the Elastic IP from the instance, AWS will not automatically assign a new public IP address to it.

To restore a public IP address to your EC2 instance, you can follow these steps:

1. Create an AMI: Generate an Amazon Machine Image (AMI) based on your existing EC2 instance. This will capture its configuration, data, and settings.

2. Launch a new EC2 instance: Use the AMI you created in the previous step to launch a new EC2 instance. During the launch process, ensure that you enable the option to auto-assign a public IP address to the new instance.

For more detailed information on EC2 instance addressing options, you can refer to the official AWS documentation here: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html

Geraxnm
answered 9 months ago

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