363

A guy I work with gave me the EC2 credentials to log onto his EC2 console. I was not the one who set it up. Some of the instances show a public dns name and others have a blank public DNS. I want to be able to connect to the instances that have a blank public DNS. I have not been able to figure out why these show up as blank.

Jacob Gabrielson
  • 34,800
  • 15
  • 46
  • 64
user1456508
  • 3,761
  • 2
  • 15
  • 11
  • 2
    Are the instances inside a VPC? Check if there is a value next to the VPC ID field in the instance description screen. – David Levesque Jan 06 '14 at 05:16
  • 1
    I have the same problem. My instances are inside a VPC, and on the Subnet, I have checked the public DNS to be available. Still I'm getting no public DNS names. I can see that in my VPC configuration, it's saying `DNS hostnames: no`, but I cannot change that value and adding a new VPC doesn't give me the selection either. – Wrench Sep 20 '14 at 12:14
  • 1
    I have different problem when setup [my-vpc](http://stackoverflow.com/a/38235022/4058484), The `DNS hostname: yes`, but it is only Private ID when the instance is started. I can only get the Public IP when an Elastic IP is used. – eQ19 Jul 18 '16 at 10:44
  • 1
    What helped me was a stop and start for the instance without the public IP/DNS (reboot didn't help). After instance was restarted, it got the public IP. – justadev Sep 20 '16 at 15:59

22 Answers22

691

I had the same problem an solved it. Have a look at the step-by-step instructions:

  • Go to console.aws.amazon.com
  • Go To Services -> VPC
  • Open Your VPCs
  • select your VPC connected to your EC2 and
  • select Actions => Edit DNS Hostnames ---> Change DNS hostnames: to YES
Halo
  • 1,730
  • 1
  • 8
  • 31
SEO Freelancer
  • 7,054
  • 1
  • 12
  • 7
  • 3
    The section containing VPCs is now called Networking. And to edit, you right-click on the VPC. – nasch May 20 '15 at 19:31
  • 115
    +1 you now also need to set your subnet to allow auto-assignment of public ip. Right click your subnet > modify auto-assign public ip > check the box – Adam Hey Aug 07 '15 at 05:56
  • 2
    Even when I tried to add an Elastic Ip, it was not working until that option to change dns hostnames was set to yes. – RenatoSz Jan 08 '16 at 15:01
  • How does doing this effect the instances that already have a Public DNS? – kraftydevil Apr 06 '16 at 17:07
  • I thought this should be done in the subnet VPC -> Subnets -> (Right Click on the) Subnet -> Modify Auto-Assign Public IP -> (Tick) Enable auto-assign public ip – Shuliyey May 09 '16 at 00:18
  • Does this impact existing instances? – Jack BeNimble Jan 19 '17 at 20:03
  • 1
    @ Jack BeNimble Yes. This will impact the existing instances in the VPC. Those instances will get the Public DNS. – Vignesh Jul 14 '17 at 06:11
  • @Vignesh But my existing instance still does not have a public DNS. – Parantap Parashar Dec 29 '17 at 10:12
  • 10
    @Vignesh I did not get a public IP or DNS for existing instances. Stopping and restarting didn't change anything. The only thing that worked was to terminate and recreate the instance. – Y     e     z Dec 03 '18 at 00:10
  • To reinforce @Yez prev comment, my problem was my existing EC2 instance still needed to be recreated for it to take effect after I made both config changes. So as numerous other posts have properly documented both config settings: VPC: Edit DNS hostnames = Enable Subnet: Auto-assign public IPv4 address = Yes Then create AMI and, relaunch the instance. – Matthew Allen Apr 08 '21 at 12:56
65

There is a actually a setting in the VPC called "DNS Hostnames". You can modify the VPC in which the EC2 instance exists, and change this to "Yes". That should do the trick.

I ran into this issue yesterday and tried the above answer from Manny, which did not work. The VPC setting, however, did work for me.

Ultimately I added an EIP and I use that to connect.

Mike T
  • 1,286
  • 11
  • 13
44

Sounds like the instance was launched in VPC and while doing so, the check-box for Automatically assign a public IP address to your instances was not checked. Hence the instance does not have a public IP

You can assign an Elastic IP to this instance and then log in using that IP.

slayedbylucifer
  • 22,878
  • 16
  • 94
  • 123
37

In my case I found the answer from slayedbylucifer and others that point to the same are valid.
Even it is set that DNS hostname: yes, no Public IP is assigned on my-pvc (only Privat IP).

It is definitely that Auto assign Public IP has to be set Enable.
If it is not selected, then by default it sets to Use subnet setting (Disable)

Assign Public IP

Community
  • 1
  • 1
eQ19
  • 9,880
  • 3
  • 65
  • 77
24

This is the tip provided to resolve the issue which does not work:

Tip - If your instance doesn't have a public DNS name, open the VPC console, select the VPC, and check the Summary tab. If either DNS resolution or DNS hostnames is no, click Edit and change the value to yes.

Assuming you have done this and you are still not getting a Public IP then go over to the subnet in question in the VPC admin screen and you will probably discover "Auto-Assign Public IP" is not set to yes. Modify that setting then, and I know you don't want to here this, create a new instance in that subnet. As far as I can tell you cannot modify this on the host, I tried and tried, just terminate it.

Bill Parker
  • 241
  • 2
  • 3
24
  1. Go to AWS Console.
  2. Go to Services and select VPC
  3. Click on vpc.
  4. select the instance and click on Action.
  5. Select Edit DNS Host name click on yes.

At the end you will get your Public dns.

  • adding Public DNS to the VPC along with the assigned Elastic IP works. For some reason, the elastic IP can be pinged from the outside world through the Security Group but hitting a web app like Solr failed unless there's a public DNS assigned.. – roguequery Jan 13 '16 at 16:10
23

For me problem was in subnet settings.

  1. Open https://console.aws.amazon.com/vpc
  2. Go to subnets in left menu
  3. Choose your subnet
  4. Modify auto-assigning IP settings to enable
Neftanic
  • 930
  • 9
  • 17
22

It is related to the VPC's feature called "DNS Hostnames". You can enable or disable it. Go to the VPC, under the Actions menu select the "Edit DNS Hostnames" item and then choose "Yes". After doing so, the public DNS of the EC2 instances should be displayed.

Lior Kirshner
  • 696
  • 5
  • 9
  • Can I use my custom names? Cuz when I send emails from my instance, Gmail shows mailed by ec2..ip address...location..etc instead of my domain name – mrid Apr 16 '20 at 04:49
  • @mrid you need to associate your DNS with the generated DNS of the EC2. You can do it with AWS Route53 service, our your hosting/DNS manager. – Lior Kirshner Apr 16 '20 at 11:35
  • 1
    Accidently I have deleted my default settings, and then I have to recreate Infrastructure, this works for me, Thanks :) – Dnyaneshwar Jadhav Sep 15 '22 at 13:13
16

Here I will summarize the most common issues that occur:

When you create a custom VPC, if you want aws resources such as ec2 instances to acquire public IP addresses so that the internet can communicate with them, then you first must ensure that the ec2 instance is associated with a public subnet of the custom VPC. This means that subnet has an internet gateway associated with it. Also, you need to ensure that the security group of the VPC associated with ec2 instance has rules allowing inbound traffic to the desired ports, such as ssh, http and https. BUT here are some common oversights that still occur:

1) You must ensure that DNS hostnames is enabled for the VPC

2) You must ensure the public subnet linked to the EC2 instance has its 'auto-assignment of public ip' flag enabled

3) If the instance is already created, then you might need to terminate it and create a new instance for the public IP and public DNS fields to be populated.

Daniel Viglione
  • 8,014
  • 9
  • 67
  • 101
  • Once this public ip is visible in the launched instance, we can use this IP to connect the instance via putty SSH – rinilnath Feb 23 '20 at 18:13
12

Just launch another instance (and also delete the one in question if it has no use) and make sure this time you check "Autoatically assign a public IP address to your instance". If not then as slayedbylucifer suggested; assign an Elastic IP (EIP) to the instance and then log in using that IP. Be careful though, if you are running the free AWS tier, an EIP will cost you money-- that's a whole 'nother topic..

Manny Fernandez
  • 121
  • 1
  • 2
7

First of all, there can be two reasons for this:

  1. You have created your own VPC and forgot to enable Public DNS.

To solve this :

i) Go to AWS VPC console and select the VPC you have created.

ii) Then click on Actions and then enable DNS Resolution.

            OR
  1. You have not enabled public ip-assign option in EC2 configuration.

Here you cannot change the setting; so create an ami image and then recreate the instance from that.

Patrick R
  • 6,621
  • 1
  • 24
  • 27
7

After verifying VPC and Subnet settings, my EC2 instance still didn't have a public DNS. After a day of searching for a resolution, I finally figured it out.

I had to create a new Elastic IP address, then associate it to my instance.

From the EC2 Dashboard:

Go to Elastic IPs from the sidebar.

Click Allocate new address, then Allocate.

Go back to the EC2 Dashboard. Go to Network Interfaces.

Select the EC2 instance without a public DNS. Then Actions - Associate Address.

The Address field, select the new elastic IP address.

The Associate to private IP address field, select the private IP address with no public DNS.

Click Associate Address.

Your EC2 instance should now have a public DNS.

BenR
  • 2,791
  • 3
  • 26
  • 36
4
  1. Go to VPC
  2. Select your VPC
  3. Click actions and choose Edit DNS hostnames
  4. Tick Enable for DNS Hostnames
  5. Click save changes
Tung Vu
  • 41
  • 3
4

The problem is that the DNS Host name in your VPC is dropped. You can easily enable it like this:

  1. Go to your instance in the console, then click your VPC ID. enter image description here

  2. In your VPC, select the Edit DNS Host names option Select Edit DNS Host names

  3. Set it to enabled and save your changes. enter image description here

  4. Now, in your EC2 instance window you can find the DNS: enter image description here

Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
2

The change to the DNS Hostnames setting can also be done using the AWS CLI:

aws ec2 modify-vpc-attribute --vpc-id $vpc_id --enable-dns-hostnames '{"Value": true}'

(Where $vpc_id is the ID of the VPC that your instance is attached to.)

As soon as the VPC is updated the instance will gain a public DNS.

Paul Pritchard
  • 614
  • 2
  • 11
  • 23
2

For those using CloudFormation, the key properties are EnableDnsSupport and EnableDnsHostnames which should be set to true

VPC: {
    Type: 'AWS::EC2::VPC',
    Properties: {
      CidrBlock: '10.0.0.0/16',
      EnableDnsSupport: true,
      EnableDnsHostnames: true,
      InstanceTenancy: 'default',
      Tags: [
        {
          Key: 'env',
          Value: 'dev'
        }]
    }
  }
  • Helpful answer, thanks. FYI the default for EnableDnsSupport is true so it's typically sufficient to indicate EnableDnsHostnames: true. – jarmod Aug 02 '17 at 14:04
1

If the instance is in VPC, make sure both "DNS resolution" and "DNS hostnames" is set to "yes". You can do this in the Aws console UI. HTH!

Trunal Bhanse
  • 1,651
  • 1
  • 17
  • 27
1

Go to VPC console, select your VPC, and click ACTIONS menu, select Edit DNS Hostnames - select Yes. That should fix it.

Kingz
  • 5,086
  • 3
  • 36
  • 25
1

I tried to fix the 'no public DNS' once the EC2 was up and running, I couldnt add a public DNS

this is even after following the above steps making mods to the VPC or the Subnet

so, I had to make modifications to the subnet and the vpc, before starting another instance, and THEN start up a new instance.

the new instance had a public DNS. That is how it worked for me.

1082E1984
  • 67
  • 1
  • 4
1

For those who are using Terraform.

To enable the DNS hostnames, use the following line in your VPC like this:

resource "aws_vpc" "app_vpc" 
{
   enable_dns_hostnames = true # Add this line

   cidr_block = var.vpc_cidr
   tags = { Name = "mostafa_vpc" }
}
Mostafa Wael
  • 2,750
  • 1
  • 21
  • 23
0

You don't have to assign public ip address to your instance. you can use NAT instances or NAT Gateway.

https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-comparison.html

Trouble
  • 11
  • 2
0

For the public IP / DNS first, you must have a running EC2 Service ( That can be Instance / Docker / Lightsail. for any of the services you will have two different IPs ( Private & Public ) also the security group available under the security Tab once you selected actively Instance.

STEP-1:

You can enable according to the port Usage like if you wanted to host a website using HTTP & HTTPS Ports

EC2->Security Group -> Edit Inbound Rules -> Added or Remove required ports.

like 80,443,22 etc and traffic source for the port ( if you want to make the port open for all select anywhere or if you want to open the application for the selected IPs- Enter IPV4/IPV6 manually.

once you are done with the above configuration, Create Elastic IP and attached it to your Running EC2 instance. Once you attached the IP with the instance your Public IP will be the Elastic IP

STEP-2:

AWS offers you one more service called Route53. Here you can create Hosted Zones and enter the domain name without www after creation, you will get the Name Server value for the hosted zone.

for more info about Route53 https://aws.amazon.com/route53/

Kishor Pant
  • 136
  • 1
  • 4