Supported Version
This manual applies to:
Centos 8
Centos 7
Introduction
When creating a brand new ONENETS VPS, you could set the server hostname earlier before deployment. if you skip this step or decide to rename your server later, you'll find out that changing the server hostname from the control portal also create a new reinstall of the complete server.
Follow this procedure if you need to change the server hostname without reinstalling the server:
SAMPLE
This configuration use olddog for the old hostname and newtricks for the new hostname
- Check the active hostname
Check the hostname with hostname.
$ hostname
olddog
You can also use hostnamectl.
$ hostnamectl
Static hostname: olddog
Icon name: computer-vm
Chassis: vm
Machine ID: 4a92996cd47145f1ba4b8ad1420bad64
Boot ID: 4515953cc80846f4a9078a7916db3819
Virtualization: kvm
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-147.8.1.el8_1.x86_64
Architecture: x86-64
2. Change Hostname
Change the hostname to newtricks.
$ sudo hostnamectl set-hostname newtricks
3. Update /etc/hosts
Use your favorite text editor to change any instances of your old hostname to the new hostname in /etc/hosts. If you have a DNS name pointed to this instance, it's a best practice to also set that name here.
$ sudo nano /etc/hosts
From:
127.0.0.1 olddog
::1 olddog
To:
127.0.0.1 newtricks newtricks.example.com
::1 newtricks newtricks.example.com
4. Confirm the Change
Reboot the server.
Test your change with hostnamectl and hostname.
$ hostnamectl
Static hostname: newtricks
Icon name: computer-vm
Chassis: vm
Machine ID: 4a92996cd47145f1ba4b8ad1420bad64
Boot ID: 4515953cc80846f4a9078a7916db3819
Virtualization: kvm
Operating System: CentOS Linux 8 (Core)
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-147.8.1.el8_1.x86_64
Architecture: x86-64
$ hostname
newtricks
$ hostname -a
newtricks.example.com
Update DNS
Your server hostname is changed and ready to use. This procedure does not change your DNS name, and you'll need to perform those steps at your domain registrar.