The hostname of your Linux system is how other devices on the network will identify your computer. Although these devices may communicate with your system via IP address, they can also use the hostname to look up your system. Apart from this, the hostname is basically just a way to keep track of what the computer is used for. For example, a database server may have a hostname like “db-server.”
How to View the Hostname in Linux
You’ll see the hostname anytime you open a terminal window, like in our Ubuntu system where the hostname is “my-server”:
You can verify the hostname of a system at any time with the
How to Change the Hostname in Linux
You can change the hostname in Linux by using the
hostnamectl command in the following syntax. You’ll need super user privileges, so either login to your root account or prefix the command with
sudo hostnamectl set-hostname ubuntu
Our hostname has now been updated, but our current terminal doesn’t reflect the change. Open a new terminal to see the updated hostname in use, or type the
hostname command again to verify a successful change.
In some distributions, it’s also possible to configure the hostname inside the GUI. For example, in the GNOME desktop environment on Ubuntu, open the Settings menu in the top right corner of the desktop.
Then, navigate to About > Device Name.
Click on “Device Name” and you’ll be able to type a different hostname to use.