我如何知道 Amazon AWS 实例的内部 DNS 名称?

发布于 2024-10-28 08:28:17 字数 156 浏览 1 评论 0原文

我有一个系统,在 Amazon AWS 云上有 N 个服务器。他们都在同一个区域。实例 A 想要与实例 B 通信,但它显然不通过互联网。据我了解,每次重新启动实例时,内部IP都会发生变化。我的所有实例是否都有一个内部、恒定的 DNS 名称,通过该名称它们可以在彼此之间进行交互,而不必担心重新启动?

I have a system that has N servers on the Amazon AWS cloud. They are all in the same zone. Instance A wants to talk to instance B, but it obviously doesn't go through the internet. As far as I understand, the internal IP changes every time I reboot the instance. Is there an internal, constant DNS name to all my instances, through which they can interact between themselves without worrying about restarts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

秋叶绚丽 2024-11-04 08:28:17

不,无法通过开箱即用的 AWS 实例来使用“固定”IP 地址或 DNS 名称。即使您为实例分配 EIP(弹性 IP),这也只会影响面向公众的 IP/DNS 引用,而不会影响内部 IP/DNS 引用。

我们在 EC2 资产中使用一对 DNS 服务器(它是 Windows,因此它们是主/辅助 AD 域控制器)。通过让所有其他实例使用这对作为其 DNS 服务器,我们可以在每个实例启动时为其分配唯一的计算机名称,并通过这些名称引用任何/所有其他实例。

例如,我们基于 EC2 的 Subversion 服务器有一个 EIP,这意味着当我们从 EC2 外部与它通信时,它始终位于同一位置,但基于 EC2 的 CruiseControl 服务器将其称为 [ourec2domain].SVNHOST,因为它注册了该名称启动时与 DC 一起使用。

No, there is no way to make use of 'fixed' IP addresses or DNS names using the out-of-the-box AWS instances. Even if you assign an EIP (Elastic IP) to the instance, this only affects the public-facing IP/DNS reference, not the internal one.

We use a pair of DNS servers in our EC2 estate (it's Windows, so they're Primary/Secondary AD Domain Controllers). By having all other instances use this pair as their DNS servers, we can assign unique machine names to each instance as they spin-up, and reference any/all other instances by these names.

So for example our EC2-based Subversion server has an EIP which means it's always at the same place when we talk to it from outside EC2, but the EC2-based CruiseControl server refers to it as [ourec2domain].SVNHOST because it registers that name with the DCs at startup.

戏蝶舞 2024-11-04 08:28:17

当我第一次开始使用云时,我也遇到了同样的问题。我也使用 2 个 DNS 服务器的设置,并使用命令 ec2-create-tags添加标签到两个服务器。 --tag Purpose=DNS

使用 http://cloudinitnet.codeplex.com 服务我创建了服务器在启动时运行 powershell 脚本。此 powershell 脚本检查亚马逊的两个 dns 服务器并将它们添加到网络接口。假设此时您有一个 dns 服务器列表,您可以使用下面的代码将条目添加到 dns 服务器。要获取服务器列表,只需使用 Powershell 使用 AWSSDKnet 查询您的帐户即可。

$connection = "Local Area Connection 2"
$registered = $false;

# Clean up the DNS entries incase there are any settings already
Write-Output "Clearing DNS Entries"
$X = netsh interface ip set dns $connection static none

$index = 1;
foreach ( $server in $servers)
{
    # Set this server's 
    Write-Output "Adding server $server to DNS"
    $X = netsh interface ip add dnsserver $connection $server index=$index

    # Register the server's hostname with the dns server
    if(-not ($registered))
    {
        $computer = hostname
        $address = (netsh interface ip show address $connection | select-string "IP Address") -replace '^[^\d]+'
        $rec = [WmiClass]"\\dns01\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
        $rec.CreateInstanceFromTextRepresentation("dns01", "network.cloud", "$($computer).network.cloud IN A $address")
        $registered = $true;
    }
    $index++;
}

如果您的服务器不是 Windows,那么您可以使用 Ubuntu 或 Amazon Linux“Cloud-Init”来执行相同的任务。

I had the same issues when I first started using the cloud. I too use a setup of 2 DNS servers and add a tag to the two servers using the command ec2-create-tags <instance> --tag Purpose=DNS

Using the http://cloudinitnet.codeplex.com service I created the server runs a powershell script on startup. This powershell script checks amazon for the two dns servers and add them to the network interface. Assuming you have a list of dns servers at this point you can use the code below to add the entries to the dns server. To get a list of servers just query your account with the AWSSDKnet with powershell.

$connection = "Local Area Connection 2"
$registered = $false;

# Clean up the DNS entries incase there are any settings already
Write-Output "Clearing DNS Entries"
$X = netsh interface ip set dns $connection static none

$index = 1;
foreach ( $server in $servers)
{
    # Set this server's 
    Write-Output "Adding server $server to DNS"
    $X = netsh interface ip add dnsserver $connection $server index=$index

    # Register the server's hostname with the dns server
    if(-not ($registered))
    {
        $computer = hostname
        $address = (netsh interface ip show address $connection | select-string "IP Address") -replace '^[^\d]+'
        $rec = [WmiClass]"\\dns01\root\MicrosoftDNS:MicrosoftDNS_ResourceRecord"
        $rec.CreateInstanceFromTextRepresentation("dns01", "network.cloud", "$($computer).network.cloud IN A $address")
        $registered = $true;
    }
    $index++;
}

If your servers are not windows then you can use Ubuntu or Amazon Linux "Cloud-Init" to perform the same task.

等往事风中吹 2024-11-04 08:28:17

从实例来看:

curl http://169.254.169.254/latest/meta-data/local-hostname

From the instance:

curl http://169.254.169.254/latest/meta-data/local-hostname
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文