I'm struggling with a strange problem on a Ubuntu 14.04.1 LTS VM running on Azure. My hostname keeps getting reverted to something related to my Azure Deployment. In short: the system hostname does not equal cat /etc/hostname while /etc/hostname and /etc/hosts remain unchanged.

This is my /etc/hostname


And this my /etc/hosts localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts dbc1mdb dbc1sdb1

I am really pulling my hair out. Any suggestions?

UPDATE: I'm now suspecting that either the DHCP client or the Azure Linux Agent is messing with the hostname.

4 Answers 4


I guess I'm a little late to the party but in Ubuntu the Ubuntu Cloud packages appear to be responsible for this. This answer should still be relevant since it is applicable to 18.04 LTS.

The configuration data for these packages appears to be in /var/lib/cloud/data, the /var/lib/cloud/data/set-hostname file in particular:

 "fqdn": "<your fqdn>",
 "hostname": "<your hostname>"

As far as I can tell the hostname is set by the configuration scripts from these packages at boot time.


It's probably a script running in the background.

You have 2 options:

1) Remove whatever is changing your hostname.

2) Change your hostname in /etc/hostname and run sudo chattr +i /etc/hostname to prevent it from being changed.

  • The strange thing is that /etc/hostname remains untouched. Aug 29, 2014 at 19:50
  • then try sudo service hostname restart && sudo ifdown eth0 && sudo ifup eth0 (it should be run on boot, if it's not then it's ubuntu's bug).
    – przemo
    Aug 29, 2014 at 19:55
  • Or sudo service hostname restart && ifconfig eth0 down && ifconfig eth0 up
    – przemo
    Aug 29, 2014 at 19:59
  • If it doesn't help change configuration in Azure Linux Agent, I think it's Image Provisioning / Setting the host name.
    – przemo
    Aug 29, 2014 at 20:03

I was experiencing the same issue in Ubuntu 22.04 server which I installed from the cloud image. For me it was cloud-init constantly resetting the hostname because I had set the hostname when creating the cloud-init config file for installing the VM.

In the end, all I had to do was disable cloud-init from running by creating an empty file at a specific location:

sudo touch /etc/cloud/cloud-init.disabled

I can do this because I set up my own guest within my own KVM host. If one is using a cloud provider, this may not be a viable solution for you as you may need cloud-init to keep running those startup steps.

I had no idea before now that cloud-init didn't just run on first setup until reading this other Ask Ubuntu post, but will run a different set of steps afterwards. For more info, here are the cloud-init boot stage docs.


Went through the same scenario and issue. Removing the cloud-init, cloud-init-utils, and walinuxagent packages cleared the issue.

sudo apt-get remove cloud-init
sudo apt-get remove cloud-init-utils
sudo apt-get remove walinuxagent

Above package names may not be accurate, and removal of dependent packages and/or configs may be called for as well. YMMV.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .