0

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?

Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
Z Jones
  • 121
  • 1
  • 3

5 Answers5

8

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.

Bart De Vos
  • 17,911
  • 6
  • 63
  • 82
  • 3
    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 06: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 07:39
  • Modified the process here to suit my needs: http://shlomoswidler.com/2010/12/using-aws-route-53-to-keep-track-of-ec2-instances.html Thanks! – Z Jones Sep 30 '11 at 00:04
  • @BartDeVos can you use Route 53 to store ` --> ` style DNS info? I don't have a domain. – DevOpsSauce May 20 '23 at 11:26
0

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

mrdenny
  • 27,174
  • 4
  • 41
  • 69
0

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...

Silverfire
  • 790
  • 4
  • 14
0

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.

Andrei Mikhaltsov
  • 3,027
  • 1
  • 23
  • 31
0

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.

Jeremy Bouse
  • 11,341
  • 2
  • 28
  • 40