Introduction
The hostname is a unique name assigned to a computer or device connected to a network. It serves as an identifier and facilitates communication with other devices on the same network.
Prerequisites
Ensure you have sudo privileges or are logged in as the root user.
Changing the Hostname Temporarily
- Check current hostname:
hostname
- Change hostname temporarily:
sudo hostname new-hostname
Changing the Hostname Permanently
- Edit
/etc/hostname
:
sudo nano /etc/hostname
- Edit
/etc/hosts
:
sudo nano /etc/hosts
- Reboot system:
sudo reboot
Using Hostnamectl Command
- Change static hostname:
sudo hostnamectl set-hostname new-hostname
- Change transient hostname:
sudo hostnamectl set-hostname --pretty new-hostname
Conclusion
Changing the hostname on Ubuntu 22.04 can be done through multiple methods, providing flexibility for system management.