Skip to content

Configure a server hostname

A recognizable hostname helps identify which server sent a cPFence notification or appears in an Owl report. For cPFence v4+ on Enhance, make this change locally on the intended Ubuntu 22.04/24.04 server with root or sudo access.

Terminal window
hostnamectl

Record the current hostname and keep a private copy of /etc/hosts before editing. Choose a unique name, such as server1.example.com; replace this example with your own name.

Terminal window
sudo hostnamectl set-hostname server1.example.com

This changes the system hostname. Review any mail or monitoring configuration that depends on the old name.

Open the file:

Terminal window
sudo nano /etc/hosts

Find the existing local hostname entry, usually:

127.0.1.1 old-hostname

Replace its old hostname with your chosen name:

127.0.1.1 server1.example.com

Preserve the localhost, IPv6, and unrelated entries. Save and close the editor.

Terminal window
hostnamectl
hostname -f

The static hostname should show the new name, and local hostname resolution should return the intended name. A new login refreshes a shell prompt that still displays the old name. In a Bash terminal you can also refresh the shell with:

Terminal window
exec bash

The hostname change itself takes effect without a reboot. Ubuntu’s server guide documents hostnamectl set-hostname for setting the name at runtime.

  • Unable to resolve host: check the spelling and matching local hostname entry in /etc/hosts.
  • Name changes back: ask the server administrator to check hostname management in the cloud provisioning or network configuration.
  • Need to undo: set the recorded previous hostname with the same command and restore its hosts-file entry from your private copy.

For notification delivery problems, use email and SMTP notifications.