Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Have any of you come up with a good way to keep the /etc/hosts file on multiple EC2 instances up to date?

Instances go down.. some new instances get created... and internal IPs change. How can I make sure the /etc/hosts file on all the servers is accurate?

share|improve this question
7  
What's wrong with DNS? –  Shane Madden Sep 29 '11 at 4:30
add comment

5 Answers

up vote 4 down vote accepted

2 options:

  • Use Elastic IP's. Whenever an instance gets the boot you can recycle the IP and use it on a new instance.

  • Use DNS: Set up a small DNS-server (dnsmasq does not require a lot of resources) on one of the instances and redirect all the primary DNS-servers on the other instances to here. Setting up or a new host is trivial as it requires no more than one line in a text file.

Maybe a combination of both wouldn't be bad either.

share|improve this answer
2  
DNS can also be managed with Amazon Route53 through an API. Saves you from having to running it on an instance and worrying about that instance going down. –  Eric Hammond Sep 29 '11 at 6:40
    
True, it would bring an extra cost with it but (I think) starting Saturday they are lowering the price for Route53. So, you have 3 possibilities :-). –  Bart De Vos Sep 29 '11 at 7:39
    
Modified the process here to suit my needs: shlomoswidler.com/2010/12/… Thanks! –  Z Jones Sep 30 '11 at 0:04
add comment

I know on the Windows side there is some sort of DNS offering that can be used. Can't you use that instead?

share|improve this answer
add comment

EDIT EC2 does not support network broadcast, Multicast DNS will not work.

Multicast DNS? no central server required but no DNS security(may not be a major problem, i dont know what your environment is). If all the ip's of all the servers suddenly change then you are still ok. Provided that everything is on the same broadcast domain, on EC2 i couldn't tell you if broadcasts work...

share|improve this answer
    
EC2 does not support network broadcast. –  Eric Hammond Sep 29 '11 at 6:39
add comment

You may use some file syncronizer like Unison http://www.cis.upenn.edu/~bcpierce/unison/ but i strongly discourage you to do it. Best way is to setup local DNS server (bind) and put all your hosts there.

share|improve this answer
add comment

I actually accomplish this through my Puppet server that configures my EC2 instances when they come up and online. I have the Puppet server export the IP address and then update the /etc/hosts file as well as the /etc/ssh/ssh_known_hosts files automatically with all known entries.

To handle servers going offline I actually wrapped the Host and Sshkey resource types as Expiringhost and Expiringsshkey and have it configured to remove exported records over a max age (for me set to 45 minutes since my check-ins should occur every 30 minutes) so that old stale entries are removed automatically as well.

Now I don't allow SSH connections between EC2 instances and force everyone to connect to the EC2 instances from a bastion host, so at this time only the bastion host has the Expiringhost <<| |>> and Expiringsshkey <<| |>> calls to update /etc/hosts and /etc/ssh/ssh_known_hosts.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.