Configuring Hostname on Linux Systems
Changing the Hostname Temporarily
To change the hostname temporarily on an Ubuntu 22.04 system, you can use the following command:
sudo hostnamectl set-hostname new-hostname
This command will immediately change the hostname for the current session. However, this change will not persist after a system reboot.
Changing the Hostname Permanently
To change the hostname permanently on an Ubuntu 22.04 system, you need to follow these steps:
-
Edit the /etc/hostname
file and replace the current hostname with the new one:
sudo nano /etc/hostname
Replace current-hostname
with your desired new-hostname
.
-
Edit the /etc/hosts
file and replace the current hostname with the new one:
sudo nano /etc/hosts
Replace all occurrences of current-hostname
with new-hostname
.
-
Apply the changes and reboot the system:
sudo reboot
After the reboot, the new hostname will be applied and persistent.
Verifying the Hostname
To verify the current hostname, you can use the following command:
hostname
This will display the current hostname of the system.
By following these steps, you can easily configure the hostname on your Linux systems, ensuring consistent and meaningful identification for your systems within the network.