开发者

How do I know the internal DNS name of an Amazon AWS instance?

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 interna开发者_开发技巧l, constant DNS name to all my instances, through which they can interact between themselves without worrying about restarts?


http://alestic.com/2009/06/ec2-elastic-ip-internal


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.


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.


From the instance:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜