一个和我一起工作的人给了我登录到他的EC2控制台的EC2凭证。不是我设的局。一些实例显示公共dns名称,而其他实例则显示空白的公共dns。我希望能够连接到具有空白公共DNS的实例。我一直无法弄清楚为什么这些显示为空白。


当前回答

对于那些正在使用Terraform的人。

如果需要启用DNS主机名,请在VPC中使用如下一行:

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

   cidr_block = var.vpc_cidr
   tags = { Name = "mostafa_vpc" }
}

其他回答

在这里,我将总结最常见的问题:

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)确保VPC已启用DNS主机名

2)您必须确保连接到EC2实例的公共子网启用了“自动分配公共ip”标志

3)如果实例已经创建,那么您可能需要终止它,并为要填充的公共IP和公共DNS字段创建一个新实例。

我也遇到过同样的问题,但我解决了。一起来看看这些步骤吧:

访问console.aws.amazon.com 业务-> VPC 打开vpc 选择EC2连接的VPC select Actions =>编辑DNS主机名 ——>修改DNS主机名为YES

首先,这可能有两个原因:

已创建VPC,但忘记开启“公共DNS”。

要解决这个问题:

i)进入“AWS VPC控制台”,选择已创建的VPC。

ii)然后单击“操作”,然后启用DNS解析。

            OR

您没有在EC2配置中启用公共ip-assign选项。

这里你不能改变设置;因此,创建一个ami映像,然后从中重新创建实例。

如果实例在VPC内,请确保“DNS解析”和“DNS主机名”均为“yes”。您可以在Aws控制台UI中完成此操作。HTH !

问题是删除了VPC中的DNS主机名。你可以像这样轻松地启用它:

进入控制台中您的实例,然后单击您的VPC ID。 在VPC中,勾选“编辑DNS主机名” 将其设置为启用并保存更改。 现在,在您的EC2实例窗口中,您可以找到DNS: