4
votes

I have created a VPC and within I created a Subnet and a Internet Gateway (attached to the VPC). In that subnet, I created a Route Table in which I set route 0.0.0.0/0 to target the Internet Gateway.

After that I launched an EC2 instance in my subnet but it has no public IP so I can't connect to it using RDP.

I tried to enable 'DNS hostnames' and 'DNS resolution' but it didn't add a public IP to my instance (even after restarting it). In my subnet, I enabled 'Auto-assign IPv4' but still no public IP.

Any clue what I'm missing here please?

2
There's default limit of 5 Elastic IP addresses per region, did you check that? - Oleksii Donoha
I'm not making use of any Elastic IP and don't want to if I can do without - Mit94
Did you enable 'Auto-assign IPv4' after launching the EC2 instance? It won't take affect retroactively. - jarmod
@jarmod Yes. But then I restarted the instance so it shouldn't be an issue I guess? - Mit94
That setting matters at launch time, and only at launch time. Changing it afterwards has no impact. Stopping and restarting doesn't change that. Anyhow, the key thing is that you cannot attach a (non-EIP) public IP after launch. So, either attach an EIP or capture an AMI of the instance and launch a new instance, this time requesting a public IP at launch. - jarmod

2 Answers

4
votes

Your instances won't automatically get public IPs attached to their ENIs after you enable 'Auto-assign IPv4' in your subnet. One possible solution without spinning up a new EC2 is to attach an Elastic IP (as @Oleksii Donoha suggested in the comment) to this instance. You can follow the aws docs to allocate an Elastic IP address and then associate it with your running instance.

Side note: It's not possible to attach an ephemeral ip to an already-created ENI or EC2 instance. See discussions here.

0
votes

Though your instance sits in public subnet, you have to make sure that 'Auto-assign Public IP' is either set to 'Enable' or 'Use subnet setting (Enable)'on Configure Instance Details page. Sometimes folks forget to check/reverify this setting while creating EC2 instances.