Your server arrives with a name such as ds12345. You see it in the prompt of every SSH session and in every line of the logs. If you have several servers, a name of your own, such as web01, tells you at a glance where you are. This guide changes the name and the one file that should match it.
The examples use Ubuntu 26.04 LTS. Run the commands as root, or put sudo in front of them.
1. See the Current Name
hostname
ds12345
2. Set the New Name
hostnamectl set-hostname web01
The change takes effect at once and no restart is needed. The name is stored in the file /etc/hostname, so it stays after a restart.
- Use only letters, digits and hyphens. Other characters are dropped:
web_01becomesweb01, andmy serverbecomesmyserver. - Your open SSH session keeps showing the old name in its prompt. Log out and in again and it reads
root@web01:~#.
3. Correct the File /etc/hosts
The file /etc/hosts still holds the old name. Open it:
nano /etc/hosts
Find the line with the address of your server. Replace the short name at its end with the new one and leave the rest as it is:
203.0.113.10 ds12345.seedhost.eu web01
Save with Ctrl+O and Enter, close with Ctrl+X. More about the editor: Edit Files on Your Server With nano.
4. Check It
hostname hostname -f
web01 ds12345.seedhost.eu
The first line is the new name. The second is the full name of the server on the Internet, which did not change.
Good to Know
- The address stays the same. The name you set here is the one the server uses for itself. You still connect to the same IP address and the same name in the Client Area.
- Logs carry the new name from the moment of the change: Find Errors in the Logs of Your Linux Server: journalctl.
- To go back, run the command of step 2 with the old name and restore the line in
/etc/hosts. - First steps on a new server: Linux Server: Quick Start Guide.
