The Network Identity Vector
When you initially install Ubuntu Server, the setup wizard asks you to provide a hostname—the fundamental identity that the machine uses to broadcast its presence on the local network. If you later repurpose that server (for example, changing it from a web server to a database node), leaving the old hostname intact will cause severe routing confusion and administrative chaos. You must surgically alter the server’s identity at the core configuration level.
How to Change Your Hostname
In modern Ubuntu environments, you should completely avoid manually editing the legacy /etc/hostname file, as doing so often fails to update the system’s dynamic networking daemons. You must use the dedicated hostname control utility.
1. Open your terminal application or connect to your server via SSH.
2. First, verify your current hostname by simply typing:
hostname
3. To execute the change, you must invoke the hostnamectl command with root privileges. For example, to change the server’s name to database-node-01, execute the following command exactly:
sudo hostnamectl set-hostname database-node-01
4. The terminal will execute the command silently.
5. Crucial Final Step: You must also update the local hosts file to ensure the server can still talk to itself. Type sudo nano /etc/hosts.
6. Look for the line that says 127.0.1.1 [old-hostname]. Delete the old hostname and type database-node-01.
7. Press Ctrl + O to save, Enter to confirm, and Ctrl + X to exit the text editor.
The hostname change is applied dynamically without requiring a full system reboot. The next time you open a fresh terminal session, the new identity will be prominently displayed at your command prompt.