Server Management

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
hostnamectl

Change the hostname

hostnamectl set-hostname new-hostname

The 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.com

Update /etc/hosts

After changing the hostname, update the /etc/hosts file to avoid slowdowns and warnings:

nano /etc/hosts

Modify the line containing the old hostname. It should be similar to:

127.0.1.1    new-hostname
127.0.1.1    server1.example.com  server1

Complete example of /etc/hosts:

127.0.0.1    localhost
127.0.1.1    server1.example.com  server1
::1          localhost ip6-localhost ip6-loopback

Verify after change

# Verify short hostname
hostname

# Verify FQDN (fully qualified domain name)
hostname -f

# Verify everything
hostnamectl status

Change hostname from VirtFusion panel

You can also change the hostname directly from the panel:

  1. Log into VirtFusion panel
  2. Select server → Options
  3. Find the Hostname field
  4. 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

On this page