A hostname is a label or name that is assigned to a device on a computer network. It is used to identify and locate the device in the network. Hostnames are typically human-readable names that correspond to an IP address, which is a numerical label that identifies a device's location on the network. Hostnames are commonly used in internet addresses, email addresses, and other network-related applications. In a local network, a hostname may be used to identify a computer or server within the network.
Changing the hostname on Ubuntu 22.04 is a simple process that can be completed in a few steps. The hostname is the name of the computer that is used to identify it on the network. This guide will provide step-by-step instructions on how to change the hostname on an Ubuntu 22.04 system.
- Access to the command line / terminal window
- Root privileges
Before you can change the hostname, it is important to know the current hostname of the system. To view the current hostname, open a terminal window and type the following command:
The output will display the current hostname of the system.
Now that you know the current hostname of the system, you can change it to the desired hostname. To do so, open a terminal window and type the following command, replacing
newhostname with your desired hostname:
Next, you need to update the
/etc/hosts file. This file contains a list of hostnames and IP addresses that are used to identify the system on the network. To open the file, type the following command:
sudo nano /etc/hosts
127.0.0.1 line to use the new hostname. For example, if your new hostname is
myhost, the line should look like this:
Save and close the file when you are done.
Finally, you need to reboot the system for the changes to take effect. To do so, type the following command:
After the system has rebooted, open a terminal window and type the following command:
The output will display the new hostname of the system.
In this guide, you learned how to change the hostname on an Ubuntu 22.04 system. You first checked the current hostname, then changed the hostname, updated the hosts file, and rebooted the system. With these steps, you can easily change the hostname on an Ubuntu 22.04 system.