I just launched a new EC2 instance in a custom VPC, and while I can see a public IP address, the "Public IPv4 DNS" field in the AWS Console is completely blank. This is preventing me from using the DNS name for my web server configuration. I’ve checked that the instance is in a public subnet and has an Internet Gateway attached to the route table. Are there specific VPC-level attributes that I need to enable to get AWS to generate the public hostname?
3 answers
The most common reason an EC2 instance lacks a public DNS name is that the DNS Hostnames attribute is disabled at the VPC level. By default, custom VPCs often have this setting turned off. To fix this, go to the VPC Dashboard, select your VPC, click on Actions, and then Edit VPC settings. Ensure that both Enable DNS support and Enable DNS hostnames are checked. Once these are enabled, AWS will automatically assign a public DNS name to any instance that has a public IP address. Note that you do not need to restart the instance; the DNS name should appear in the console within a few seconds of updating the VPC settings.
If you have already enabled those VPC settings and still don't see the DNS name, check if your instance actually has a Public IP. If the instance was launched without the "Auto-assign Public IP" setting enabled, it won't receive a Public DNS name because there is no public address to map it to. In this case, you would need to associate an Elastic IP (EIP) with the instance. Once the EIP is attached, the Public DNS name should generate automatically using the EIP's address format.
It's almost always the VPC setting. Just a heads-up: if you are using a CLI or Terraform to build your VPC, you have to explicitly set enable_dns_hostnames = true, as it defaults to false in many automated scripts.
Thanks Rebecca! I checked my Terraform code and that was exactly the issue. I added the attribute, ran terraform apply, and the DNS names appeared instantly across all my instances.
Justin makes a great point. I’ve also noticed that if you are using a strictly private subnet with a NAT Gateway, you will never get a Public DNS. The DNS hostname is specifically tied to the public-facing side of the network. If your architecture requires public access, make sure your subnet's Route Table has a path (0.0.0.0/0) leading to an Internet Gateway (IGW), otherwise the "Public" part of the DNS won't trigger.