OVH VPS – Change Hostname

I have had a few Virtual Private Servers (VPS) with OVH and have had no issues with them at all, despite the mixed reviews out there. Although their support is somewhat lacking, their network is great! Anyway I digressed.

The few servers I have had with them have always been Linux; Ubuntu & Centos and when configuring them you usually want to set the hostname to something more meaningful other than the random string of numbers that OVH assign by default. In the ideal world I would just change the hostname by doing the below.

root@ovhserver:~$ sudo nano /etc/hostname
servername

OVH operates a cloud-init program which pulls the information from their Public Cloud and assigns to on reboot, which is great unless if you are running a webserver or email server and need a static hostname. What you will need to do is disable the cloud-init program and set the hostname as desired to stop it from being reset at next reboot.

Disable cloud-init

root@ovhserver:~$ sudo nano /etc/cloud/cloud.cfg

Find the below entries and change

preserve_hostname: true
manage_etc_hosts: false

Changing the Hostname

root@ovhserver:~$ sudo nano /etc/hostname
servername

Edit the hosts file

root@ovhserver:~$ sudo nano /etc/hosts
192.168.0.1 mailserver.localdomain mailserver
192.168.0.1 localhost

Reboot the server for the changes to take effect

root@ovhserver:~$ sudo reboot now

After the reboot confirm the hostname is as you set earlier

root@ovhserver:~$ sudo cat /etc/hosts
192.168.0.1 mailserver.localdomain mailserver
192.168.0.1 localhost

1 Comment on "OVH VPS – Change Hostname"

  1. Hi. thanks for the details but i have a question. Beside using a better name for the server, is it better to change the hostname for any other reasons? Cheers

Leave a comment

Your email address will not be published.


*