Lost modified /etc/hosts file on Amazon EC2 every reboot instance?

I have setup an Ubuntu 8.10 server instance on Amazon EC2. I install ejabberd on server, but I face some problems on ejabberd node can't start because hostname on cloud changes each time we relaunch the instance. After I follow this link http://blog.kenweiner.com/2008/05/ejabberd-on-amazon-ec2-ubuntu-ami.html to edit and add hostname in /etc/hosts file, it works. Unfortunately, every time I reboot the server, the /etc/hosts file get reset to default.

How could I solve this problem?


Solution 1:

This is a known problem with the current Ubuntu images for EC2 built by Canonical:

https:// bugs.launchpad.net/ubuntu-on-ec2/+bug/371936

You can wait for the next release from Canonical or run the Ubuntu images for EC2 which I publish on http:// alestic.com (and which do not have the same problem).

I have successfully run ejabberd on the Alestic.com images.

Solution 2:

I know this a super old thread but one the pops up on ggl, yes it is cloud-init, on my debian ami I added my custom entries in:

/etc/cloud/templates/hosts.debian.tmpl

lets see if that works on next auto-reboot by

aws ec2 create-ami ...

Solution 3:

You could try CloudInit to perform your hosts file cleanup during instance boot. It is included in all the current official Ubuntu EC2 images and allows you to run initialization scripts passed by the --user-data switch of ec2-run-instances (or the respective input field(s) in the AWS Console wizard) which will be run at boot. Kind of like rc.local.

Edit: I did not realize it was Eric himself who wrote the other comment, at first. He's got lots of useful entries in his blog at Alestic, including one regarding the mentioned UserData.