Changing the hostname on a Linux system like Ubuntu is a straightforward task. For users needing to change hostname on Ubuntu 22.04 Jammy Jellyfish or its older stable release of Ubuntu 20.04 Focal Fossa, this introduction outlines the process and its importance in network identification and personalization.
Key Points:
- Network Identification: The hostname is crucial for identifying your computer on a network, making it essential for network administration and maintenance tasks.
- Device Personalization: Changing the hostname allows for personalization, helping users quickly and easily identify their devices, especially in environments with multiple machines.
- Simple Process: With Ubuntu, changing the hostname is a simple command-line task that even users new to Linux can easily execute.
- Immediate Recognition: Once the hostname is changed, the device is immediately recognizable with the new name on the network, facilitating smoother navigation and management for users.
Considering these considerations, the following guide will walk you through the steps to efficiently change the hostname on Ubuntu 22.04 or 20.04, enhancing your device’s network identity and personalization.
Change Hostname with the “hostnamectl” Command
Step 1: Open the Ubuntu Terminal
To begin, open the terminal. You can access the terminal by clicking on the application launcher’s terminal icon or using the keyboard shortcut CTRL + ALT + T.
Step 2: Execute the “hostnamectl” Command on Ubuntu
Once the terminal is open, enter the following command, replacing “new-hostname” with your desired hostname:
sudo hostnamectl set-hostname new-hostname
For example, if you want to change the hostname to “ubuntu-linux”, you would enter:
sudo hostnamectl set-hostname ubuntu-linux
Verify the Host Name Changes on Ubuntu
After executing the command, close the terminal. Then, reopen the terminal using the CTRL + ALT + T shortcut, and enter the following command to verify that the hostname has been updated:
hostname
Change Hostname by Editing the Hostname File on Ubuntu 22.04 or 20.04
Edit the Hostname File on Ubuntu
Alternatively, you can change the hostname by editing the /etc/hostname file, replacing the current hostname with the desired one. To open the file for editing, enter the following command in the terminal:
sudo nano /etc/hostname
Locate the line containing the old hostname and replace it with the new hostname. Save the changes by pressing CTRL + X, Y, and Enter.
Reboot the System
After making the changes, you must reboot the system for the changes to take effect. Enter the following command in the terminal:
sudo reboot
Verify the Changes
Once the system has restarted, open the terminal using the CTRL + ALT + T shortcut and enter the following command to verify that the hostname has been updated:
hostname
Closing Thoughts
In conclusion, changing the hostname on Ubuntu can be done using the hostnamectl set-hostname command or editing the /etc/hostname file. The hostnamectl set-hostname command is the recommended method, as it is a more efficient and user-friendly way to change the hostname. However, editing the /etc/hostname file is a viable alternative if the command is unavailable on your system. Remember to reboot the system after making changes to ensure the new hostname takes effect.