How to Change the Hostname in Linux

A prompt from GNOME in Ubuntu in which you can type a new hostname

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”:

A terminal showing the hostname of a Linux system

You can verify the hostname of a system at any time with the hostname command:


Terminal output of the hostname command

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:

sudo hostnamectl set-hostname ubuntu

Terminal using the hostnamectl command to change hostname of the system

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.

Opening Settings menu from top right corner of the GNOME desktop in Ubuntu

Then, navigate to About > Device Name.

Navigating to About and then Device Name from within the Settings menu

Click on “Device Name” and you’ll be able to type a different hostname to use.

The Rename Device dialog box is asking for a new hostname

Leave a Reply

Your email address will not be published. Required fields are marked *