With Digital Ocean, I'm able to set a fully qualified domain name before starting it and I sorely miss this feature with AWS EC2.

Currently I manually go into a newly started Ubuntu 16.04 LTS instance and:

  1. sudo hostnamectl set-hostname myhost.example.com
  2. sudo vim /etc/hosts and append myhost.example.com to the line
  3. Optionally goto Route 53 panel & set it up if I want it to resolve
  4. And then run the chef scripts.

Am I missing a trick? I can't see any Route 53 / EC2 integration either.


To just set the hostname (without Route53), you can use cloud-init configuration in the user-data

hostname: mynode
fqdn: mynode.example.com
manage_etc_hosts: true
  • That's a good solution for 1&2 which I tested & confirm it works. Thank you. – hendry Jul 5 '16 at 6:35
  • 1
    No need to set hostname: "If both fqdn and hostname are set, fqdn will be used." cloud-init#set-hostname – ciastek Feb 22 '18 at 1:58
  • Perfect this was driving me crazy, thanks! I had been using user-data to run a script at boot but that's easy enough to accommodate by using a runcmd: section in the cloud-config yaml. Luckily my script is pretty basic but could see this being an issue if it were complex. – Diffuser Dec 4 '18 at 21:29
  • Is it possible to add an instance id to the hostname in cloud-config? – kivagant Apr 15 '19 at 16:34

You can use the user-data function of the console and/or API to provide a bash script which will be executed on first boot. This script can set the hostname, create a DNS record, and any other actions you desire.

  • 1
    Would be nice to see an example of this script. =) – hendry Jul 5 '16 at 2:39
  • 1
    There are hundreds of bash script examples around the internet. Dig in and give it a try? – EEAA Jul 5 '16 at 2:40
  • i just tried this. a bash script of "hostnamectl set-hostname curl -s" doesn't work. It seems that the user-data runs before the cloud-init sets the hostname ? and using the cloud-config hostname you can't give dynamic info to ? – Sirex Jun 28 '17 at 0:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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