The Network Identity Vector
When you initially provision an Ubuntu server, the hosting provider often assigns it a generic, mathematically generated Hostname (e.g., `ip-172-31-45-89`). This string serves as the server’s primary identity on the local network. Operating multiple servers with unreadable identities guarantees catastrophic administrative errors during SSH sessions. You must instruct the Linux kernel to permanently overwrite this default string with a highly contextual, human-readable identifier (e.g., `production-database-01`).
How to Change the Hostname
Modern Ubuntu deployments utilize the `hostnamectl` utility to safely manipulate this core identity string without requiring manual edits to multiple configuration files.
1. Open your terminal application or connect to the server via SSH.
2. The Identity Verification:
* Before altering the identity, verify the current state.
* Type `hostname` and press Enter. The terminal will output the current active string.
3. The Execution Command (`hostnamectl`):
* Because you are modifying the foundational identity of the operating system, you must possess root privileges.
* The syntax is: `sudo hostnamectl set-hostname [new_name]`
* To rename the server to `web-server-alpha`, type the following command:
sudo hostnamectl set-hostname web-server-alpha
* Press Enter and provide your administrative password.
* Rule: Hostnames must only contain lowercase letters, numbers, and hyphens. Do not use spaces or special characters.
4. The Local Resolution Override (The /etc/hosts File):
* While `hostnamectl` changes the primary identity, the server relies on a secondary, legacy configuration file to translate its own name into the localhost IP address (127.0.0.1). If you skip this step, certain applications will crash.
* Open the hosts file using a text editor:
sudo nano /etc/hosts
* Look at the first two lines. You will see `127.0.0.1 localhost` and likely `127.0.1.1 old-hostname`.
* Carefully delete the old hostname and type your exact new hostname (e.g., `web-server-alpha`).
* Press Ctrl+O then Enter to save, followed by Ctrl+X to exit.
5. Verification: The new identity is already active. If you close your SSH connection and log back in, your terminal prompt will instantly reflect the new nomenclature (e.g., `user@web-server-alpha:~$`).