Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2 instance in public subnet has no public IP

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?

like image 405
Mit94 Avatar asked Apr 29 '20 17:04

Mit94


2 Answers

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.

like image 160
jellycsc Avatar answered Sep 22 '22 01:09

jellycsc


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.

like image 45
Syed G Ali Avatar answered Sep 19 '22 01:09

Syed G Ali