The hostname of a computer identifies it within a local network. In Ubuntu, it appears when launching the terminal. Although the hostname is set during installation, you may need to change it to match new roles or naming conventions.
Ubuntu stores the hostname in the /etc/hostname file. You can change it by editing this file or using the hostnamectl utility, which simplifies the process.
You can verify the change by checking the /etc/hostname file and running the hostname command. Rebooting the system ensures the new hostname is recognized system-wide.
Steps to change system hostname in Ubuntu:
- Launch the terminal.
- Check the current hostname using the hostname command.
user@host:~$ hostname host
- Set the new hostname using hostnamectl.
user@host:~$ sudo hostnamectl set-hostname newhostname [sudo] password for user:
- Check the content of the /etc/hostname file.
user@host:~$ cat /etc/hostname newhostname
- Run the hostname command again to confirm the hostname change.
user@host:~$ hostname newhostname
- Run a new shell to see the change in the shell prompt.
user@host:~$ bash user@newhostname:~$
This only works if $PS1 is set to display the hostname.
- Reboot your system for the change to be applied system-wide (optional).
user@newhostname:~$ sudo reboot
This guide is tested on Ubuntu:
Version | Code Name |
---|---|
22.04 LTS | Jammy Jellyfish |
23.10 | Mantic Minotaur |
24.04 LTS | Noble Numbat |
Author: Mohd
Shakir Zakaria
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Mohd Shakir Zakaria is an experienced cloud architect with a strong development and open-source advocacy background. He boasts multiple certifications in AWS, Red Hat, VMware, ITIL, and Linux, underscoring his expertise in cloud architecture and system administration.
Discuss the article:
Comment anonymously. Login not required.