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
.