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

I have a system with N servers in the Amazon AWS cloud. All of them are in one zone. Instance A wants to talk to instance B, but it obviously does not go through the Internet. As far as I understand, the internal IP changes every time I reload the instance. Is there an internal permanent DNS name for all my instances through which they can interact with each other without worrying about reboots?

+4
source share
4 answers

No, it’s not possible to use β€œfixed” IP addresses or DNS names using AWS instances out of the box. Even if you assign an EIP (Elastic IP) instance to the instance, this only affects the public IP / DNS link, not the internal one.

We use a couple of DNS servers in our EC2 repository (this is Windows, so they are primary / secondary domain controllers). Due to the fact that all other instances use this pair as their DNS servers, we can assign unique machine names for each instance as they are promoted and refer to any / all other instances of these names.

So, for example, our EC2-based Subversion server has EIP, which means it is always there when we talk to it from outside EC2, but the EC2-based CruiseControl server refers to it as [ourec2domain] .SVNHOST because it registers this name with domain controllers at startup.

+2
source

I had the same problems when I first started using the cloud. I also use the configuration of 2 DNS servers and add the tag to the two servers with the command ec2-create-tags <instance> --tag Purpose=DNS

Using the http://cloudinitnet.codeplex.com service, I created a server when starting the powershell script server. This powershell script checks Amazon for two DNS servers and adds them to the network interface. Assuming you currently have a list of DNS servers, you can use the code below to add records to the DNS server. For a list of servers, simply request your account using AWSSDKnet using 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 Write-Output "Adding server $server to DNS" $X = netsh interface ip add dnsserver $connection $server index=$index # Register the server 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, you can use Ubuntu or Amazon Linux "Cloud-Init" to accomplish the same task.

0
source

From the instance:

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

Source: https://habr.com/ru/post/1346037/


All Articles