63

I launched an Amazon Web Service (AWS) EC2 Instance, t2.micro, which must be launched into a VPC.

The VPC has Auto-assign Public IP set to Yes.

DNS resolution: Yes

DNS hostnames: Yes

But on the EC2 Dashboard, the instance still has a blank Public DNS and Public IP. I have tried to restart the instance several times, but it still has not been assigned a Public IP. The 5 Elastic IPs that came with our AWS account have already been used. Is it possible to get a Public IP assigned to a t2.micro instance without using Elastic IP?

I have read the post: EC2 instance has no public DNS, but I do not have reputation points to be able to add a comment, so I am posting this as new question.

Pablo Guerrero
  • 936
  • 1
  • 12
  • 22
J21042
  • 1,214
  • 4
  • 19
  • 33
  • I was able to launch another instance, t1.micro, without using the VPC, and had no trouble with getting a public IP. So I don't know why the VPC - Auto Assign Public IP didn't work, but I am not loosing sleep over it. – J21042 Nov 03 '14 at 19:50

15 Answers15

80

Rightclick on the VPC row in the VPC management console page and select "EDIT DNS Hostname". Set it to "Yes". It´s necessary to allow all the instances with the same VPC.

When you create the new instance in the "Step 3: Configure Instance Details", you need to enable "Auto-assign Public IP".

That´s it! :-)

sumitya
  • 2,631
  • 1
  • 19
  • 32
Laura Liparulo
  • 2,849
  • 26
  • 27
55

The most common cause of no public IP address for your EC2 instance is that you're launching your EC2 instance in a private subnet. A private subnet means that any EC2 instances located in that subnet are not directly addressable from the public Internet. In other words, by definition, EC2 instances in a private subnet cannot have a public IP address.

This would explain why checking "public IP address" has no effect, and why you're unable to assign an Elastic IP address.

You can't just relocate an instance from one subnet to another. If you need to do that, you can create an AMI of your instance (right-click on the EC2 instance and click create image), and then launch a new instance from that AMI in a different subnet.

To determine if your subnet is private, look at the Route Table and see if you have an Internet Gateway route. Go to VPC > Subnets > Select a Subnet > Route Table tab. Look for an entry that has something like igw-***. If you see this, it's a public subnet. If you see something like eni-*** / i-***, it's a private subnet.

Josh Padnick
  • 3,157
  • 1
  • 25
  • 33
  • 1
    I can't be 100% certain that that is what happened, since I have already deleted the VPC and Route Tables that were used, but its the best explanation I have heard. I have since created a new t2.micro instance, using a new VPC, with "Auto Assign Public IP" = yes, and the public IP worked just as expected. Thank you Josh Padnick. – J21042 Nov 06 '14 at 16:24
  • An Internet Gateway does not actually give your instances a public IP. It's just a resource through which you can send and receive network traffic to and from the Internet. Try putting your instance in a public subnet, which is a subnet that routes 0.0.0.0/0 to the IG. – Josh Padnick Oct 01 '20 at 05:23
33

Also check:

VPC -> Subnets -> Subnet Actions -> Modify Auto-Assign Public IP
sumitya
  • 2,631
  • 1
  • 19
  • 32
Adam Jimenez
  • 3,085
  • 3
  • 35
  • 32
  • This should be chosen as the most correct answer as it enables the feature "automatically" on provisioning instances in the future. Thanks mate! – Alaa Salah Feb 16 '19 at 10:49
  • Banging my head against the wall for almost an hour and this fixes the problem. Thanks – pveentjer Mar 02 '20 at 14:25
  • Also make sure that `Auto-assign public IPv4 address` is set to `Enabled` when you create the EC2 instance. – famzah Nov 22 '21 at 07:35
13

Hmm. So many responses. All of them on the order of "you did something wrong."

Newsflash: AWS doesn't always work correctly. I've used AWS for a very long time. I've personally witnessed instances that do not start, instances that do not stop, disk corruptions on deployed instances and network failures on running instances.

I've never seen a case where a public IP was not created. Until this morning. Now I can add that to the list.

For the record - here's what I verified :)

  • Three identical instances in the cluster
  • All instances are in the same availability zone
  • All instances have same VPC
  • VPC DNS settings are correct (resolution / hostnames enabled)
  • All instances have same subnet
  • Subnet has: a) public routing table; b) option enabled to create public IP
  • Plenty of IP space available in the subnet

Two of the three instances receive a public IP. The third does not.

So for any others in the future getting to this post: No, you are not insane. Yes, it is possible that AWS screws up.

In our case, manually terminating the problem instance and issuing a new cluster up..."fixed" the problem.

And - I upvoted the answer that indicated a "launch more like this" from a STOPPED instance had an impact on public IP. Not because it is the correct answer (it is not) but because it demonstrates an admirable response to an otherwise inexplicable situation: trial and error / experimentation. The good old "Gee, what happens if I try this...". As cloud professionals: If all other standard troubleshooting steps fail and the only alternative is to blow away the instance (or subnet, or Lambda function, or DynamoDb, or SNS queue; whatever the failing resource) then it's wise to think outside the box and try other actions.

In other words: keep an open mind.

user1318024
  • 342
  • 2
  • 6
  • Bless you for sharing this and saving my sanity – Neil Jul 27 '21 at 13:03
  • I wish I cud give this answer a medal. I just terminated my instances and relauched the exact same using the same terraform template. It has public ips now. mofos – Red Bottle Jan 06 '22 at 14:56
12

Face the same issue today. My EC2 instance has no public DNS thus I'm unable to connect via ssh.

I tried and success with these steps:

  • Go to VPC > Internet Gateways: make sure an Internet Gateway is created and attached to the EC2's VPC

  • Goto VPC > Route Tables, select a VPC route, navigate to Routes tab: add a new rule with

++ Destination: 0.0.0.0/0

++ Target: select the created Internet Gateway

  • Goto VPC > Subnet > Route Table tab: click edit, change to the Route Table with destination 0.0.0.0/0 above

Done.

sumitya
  • 2,631
  • 1
  • 19
  • 32
Trung Lai
  • 123
  • 1
  • 5
  • Those are the only steps that made it work for me. Without this step of editing the route table, it was impossible to connect, even though it showed that the instance had a public DNS address. +1 – Arnaud A Oct 26 '18 at 01:13
7

Go to VPC -> Subnets And make sure that the Auto-assign public IPv4 address is set to YES

Nathan B
  • 1,625
  • 1
  • 17
  • 15
6

There are many possible reasons. Check the follow.

You need to have a VPC created.

The DNS resolution and DNS hostnames should be enabled.

Choose your VPC -> Actions -> Edit DNS resolution -> enable
Choose your VPC -> Actions -> Edit DNS hostnames -> enable

Into the VPC maybe you need a private and public subnet.

In the private subnet, you need to have a NAT Gateway associate to this. In the public subnet, you need to have an Internet Gateway associate to this.

You need to enable the auto-assign IP for your public subnet.

Choose the public subnet -> Actions -> Modify auto-assign IP settings -> enable

Later when you launch a new instance in Step 3: Configure Instance Details.

You should choose your VPC and your public subnet. And in the "Auto-assign Public IP" section choose "Use subnet setting (Enabled)"

I think that that should solve your problem...

sumitya
  • 2,631
  • 1
  • 19
  • 32
Jose N
  • 151
  • 2
  • 7
3

I had the same issue. The reason of my issue turned out to be that I was using a route table which was not associated with a subnet.

enter image description here

After I changed my subnet, my instances were assigned public ips.

panc
  • 817
  • 2
  • 14
  • 30
2

After creating a Subnet - make sure the Auto-assign public IPv4 setting is set to Yes or Enabled. After making sure the above setting is turned on - then launch the EC2 instance. If the above setting is not enabled after Subnet creation - the EC2 instance will be treated as Private and won't have a public IPV4 address.

2

When I use "launch more like this" option from a STOPPED instance, I'll get a new instance without a public ip. But if I "launch more like this" from a running instance, the new instance has a public ip.

xyz
  • 115
  • 3
2

Most likely, the public subnet has no enabled feature for "Auto-assign IPv4". It is selected as "No". And during your instance creation process the default option is "Use subnet setting (Enabled)". That's why newly issued instances cannot get public IP address.

Go VPC dashboard and click Subnets. Select a public subnet and select Modify auto-assign IP settings from Actions list and check Auto-assign IPv4. After saving your changes, your instances will get public IP automatically.

Ali Emre Çakmakoğlu
  • 864
  • 2
  • 12
  • 24
1

My big "gotcha" on this was when creating a VPC & Subnets from a CloudFormation stack, my Subnets were missing the Property "MapPublicIpOnLaunch" : true.

dewhacker
  • 71
  • 1
  • 5
1

My Observation :

You need to enable the auto-assign IP for your public subnet. Choose the public subnet -> Actions -> Modify auto-assign IP settings -> enable

Only after the above is done, then launch an EC2 instance and you will start seeing public IP assigned. Once an EC2 instance created without above setting enabled, that EC2 will not have public IP assigned even after reboot , it already considered that subnet to be private. Hope this helps!

1

I had the instance attached to a Subnet, which had VPC has Auto-assign Public IP set to No. I changed it to Yes and rebooted the instance. However, this didn't solve the problem.

I had to terminate the instance and create a new one, attaching it to the above Subnet (with settings already Yes before instance creation) for the instance to get a public IP.

M3RS
  • 6,720
  • 6
  • 37
  • 47
0

My Answer:

Please check if you attached a secondary network interface with the instance. As per AWS Documentations, If you attach another network interface to your instance, your current public IP address is released when you restart your instance. Please read the third point from below.

You cannot manually associate or disassociate a public IP (IPv4) address from your instance. Instead, in certain cases, we release the public IP address from your instance, or assign it a new one:

  1. We release your instance's public IP address when it is stopped, hibernated, or terminated. Your stopped or hibernated instance receives a new public IP address when it is started.

  2. We release your instance's public IP address when you associate an Elastic IP address with it. When you disassociate the Elastic IP address from your instance, it receives a new public IP address.

  3. 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.

  4. If your instance's public IP address is released while it has a secondary private IP address that is associated with an Elastic IP address, the instance does not receive a new public IP address.

AWS Documentation Link for more reference: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-instance-addressing.html?icmpid=docs_ec2_console#concepts-public-addresses