简体   繁体   English

如何解析 AWS EC2 的主机名

[英]How to resolve hostname of AWS EC2

I try to access a service in an AWS EC2 I installed.我尝试访问我安装的 AWS EC2 中的服务。 It showed error:它显示错误:

do not know what is ip-10-124-123-122不知道什么是ip-10-124-123-122

How to resolve the private hostname of the EC2: ip-10-124-123-122 ?如何解析 EC2 的私有主机名: ip-10-124-123-122

This two links show I can change hostname of the ip-10-124-123-122 to the domain name of the EC2:这两个链接显示我可以将ip-10-124-123-122的主机名更改为 EC2 的域名:

  1. set enableDnsHostnames and enableDnsSupport to true in VPC: Using DNS with Your VPC - Amazon Virtual Private Cloud在 VPC 中将enableDnsHostnamesenableDnsSupport设置为 true: 将 DNS 与您的 VPC 结合使用 - Amazon Virtual Private Cloud

  2. change hostname from ip-10-124-123-122 to domainname : Changing the Hostname of Your Linux Instance - Amazon Elastic Compute Cloud将主机名从ip-10-124-123-122更改为domainname更改 Linux 实例的主机名 - Amazon Elastic Compute Cloud

Note I do have a domain name for the webserver of EC2:port 80 but it is nothing to do with the hostname of the EC2.注意我确实有 EC2 的网络服务器的域名:端口 80,但它与 EC2 的主机名无关。 Because I created the domain name using this way:因为我使用这种方式创建了域名:

https://domainname->route53->ALB:443->targetgroup->EC2 port 80. 

Note: the EC2 is in a non-default VPC and the VPC already has DNS resolution and DNS hostnames enabled.注意:EC2 位于非默认 VPC 中,并且 VPC 已启用 DNS 分辨率和 DNS 主机名。

If I type nslookup ip-10-XXX.region.compute.internal at an EC2 in the same subnet of that EC2, I can see the IP but the IP of that EC2 is not resolved.如果我在该 EC2 的同一子网中的 EC2 上键入nslookup ip-10-XXX.region.compute.internal ,我可以看到 IP 但该 EC2 的 IP 未解析。

If I type nslookup ip-10-XXX.region.compute.internal in my machine where I try to access the service;如果我在尝试访问该服务的机器中键入nslookup ip-10-XXX.region.compute.internal

Note: if I nslookup ip-10-124-123-122 won't get EC2 resolved.注意:如果我nslookup ip-10-124-123-122将无法解析 EC2。 maybe this is the reason?也许这就是原因?

Are the above steps enough to resolve the hostname of the EC2?以上步骤是否足以解析 EC2 的主机名? if not.如果不。 how to resolve the error: do not know what is ip-10-124-123-122 ?如何解决错误:不知道ip-10-124-123-122是什么?

Each Amazon EC2 instance has a Public DNS Name and a Private DNS Name .每个 Amazon EC2 实例都有一个Public DNS Name和一个Private DNS Name

The Public DNS Name will look something like this:公共 DNS 名称将如下所示:

ec2-54-252-207-11.ap-southeast-2.compute.amazonaws.com

This can be resolved on the Internet.这可以在互联网上解决。 It will actually be resolved to 54.252.207.11 as suggested by the name.正如名称所暗示的那样,它实际上将解析为54.252.207.11

The Private DNS Name will look something like this:私有 DNS 名称将如下所示:

ip-172-31-10-201.ap-southeast-2.compute.internal

It will be resolved to 172.31.10.201 .它将被解析为172.31.10.201

The private DNS Name can only be resolved within the VPC where it exists .私有 DNS 名称只能在它存在的 VPC 内解析。 This is because the IP address only makes sense within that private network.这是因为 IP 地址仅在该专用网络中才有意义。

From a computer on the Internet, I can resolve the public address:从互联网上的一台计算机,我可以解析公共地址:

$ nslookup ec2-54-252-207-77.ap-southeast-2.compute.amazonaws.com
Server:     192.168.1.1
Address:    192.168.1.1#53

Non-authoritative answer:
Name:   ec2-54-252-207-77.ap-southeast-2.compute.amazonaws.com
Address: 54.252.207.77

From an Amazon EC2 instance within the same VPC, I can resolve the internal IP address:从同一 VPC 中的 Amazon EC2 实例,我可以解析内部 IP 地址:

$ nslookup ip-172-31-10-201.ap-southeast-2.compute.internal
Server:     172.31.0.2
Address:    172.31.0.2#53

Non-authoritative answer:
Name:   ip-172-31-10-201.ap-southeast-2.compute.internal
Address: 172.31.10.201

Bottom line: It appears you are not using the full DNS Name , which is why it is not working for you.底线:您似乎没有使用完整的 DNS Name ,这就是它不适合您的原因。 This is like trying to resolve facebook instead of facebook.com .这就像试图解决facebook而不是facebook.com It will not work.不起作用。 (Well, it will if you define a default network search domain, but that's not really suitable here.) (好吧,如果你定义一个默认的网络搜索域,它会,但这并不适合这里。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM