OVH Guides

Changing the hostname of an instance

Changing the hostname of an instance

The cloud-init program not only lets you configure your Public Cloud instance when you create it but also each time you reboot. Therefore, if you want to reconfigure your hostname, whether due to an error when creating your instance, or because you need to reconfigure your mail server for example, you will need to disable the cloud-init program that configures the hostname, to prevent it from being reset.

This guide explains how to reconfigure cloud-init so that you can change your instance hostname.


  • An instance

Disabling the cloud-init program

  • Edit the configuration file:
admin@serveur-1:~$ sudo vim /etc/cloud/cloud.cfg
  • Edit the status of these modules:
preserve_hostname: true
manage_etc_hosts: false

Changing the host name

  • Edit the /etc/hostname file:
admin@serveur-1:~$ sudo vim /etc/hostname

  • Edit the /etc/hosts file:
admin@serveur-1:~$ sudo vim /etc/hosts webserver.localdomain webserver localhost
  • Reboot the instance
admin@serveur-1:~$ sudo reboot

Following the reboot the host name change has been correctly registered:

admin@webserver:~$ sudo cat /etc/hosts webserver.localdomain webserver localhost

These guides might also interest you...