Change Hostname
How to change the server hostname and correctly update all configuration files
The hostname is the name with which the server identifies itself on the network. It should be set correctly especially if the server sends emails or is part of a more complex infrastructure.
View current hostname
hostname
hostnamectlChange the hostname
hostnamectl set-hostname new-hostnameThe hostname must be a valid name: only letters, numbers and hyphens. No spaces or special characters. If you want to use an FQDN (e.g. server1.example.com):
hostnamectl set-hostname server1.example.comUpdate /etc/hosts
After changing the hostname, update the /etc/hosts file to avoid slowdowns and warnings:
nano /etc/hostsModify the line containing the old hostname. It should be similar to:
127.0.1.1 new-hostname
127.0.1.1 server1.example.com server1Complete example of /etc/hosts:
127.0.0.1 localhost
127.0.1.1 server1.example.com server1
::1 localhost ip6-localhost ip6-loopbackVerify after change
# Verify short hostname
hostname
# Verify FQDN (fully qualified domain name)
hostname -f
# Verify everything
hostnamectl statusChange hostname from VirtFusion panel
You can also change the hostname directly from the panel:
- Log into VirtFusion panel
- Select server → Options
- Find the Hostname field
- Enter the new hostname and save
The change from VirtFusion panel updates the hostname at the VM configuration level, but you still need to update /etc/hostname and /etc/hosts inside the server to make the change effective on the OS.
Hostname and email
If the server sends email, the hostname affects reputation. Always use a hostname that corresponds to a valid DNS record. See: Reverse DNS
The Reverse DNS (PTR record) should match the server's hostname. Example:
- Hostname:
mail.example.com - PTR record of IP:
mail.example.com - A record:
mail.example.com→ server IP