How to change hostname in Linux

There are many reasons why you might want to change the hostname of your Linux system. Unfortunately, changing hostname is not an intuitive process.

However, don't worry, TipsMake will show you how you can change your machine's hostname in less than a minute with just a few clicks and commands.

Although this tutorial uses Ubuntu to illustrate the steps required when changing hostname, these commands should work on other Linux distributions as well.

What is hostname?

All computers connected to the network have an IP address and hostname. Hostname is the name used to identify a computer on a network in a "human readable" form. Without the hostname, when you try to locate a computer on the network, all you see is the number or IP address, like 127.0.0.1.

While IP addresses are a great way for computers to identify each other, they are not suitable for helping users identify specific computers. Let's say you want to set up a network shared folder on an Ubuntu system. If someone wants to access that folder, they'll find it much easier if they see your computer on the network showing up as 'larry-laptop' rather than '192.168.0.24'.

A common reason to switch hostnames is to avoid having the same name on the same network. For example, Ubuntu sets the hostname of all new installations to 'ubuntu' by default. If you have multiple computers on your home network and want them all to run Ubuntu Linux, you will have to change the default hostname to avoid problems.

How to change hostname through system settings

The easiest way for most people to change the hostname on a Linux machine is to go into system settings and click About. The computer's current name will appear as the first item in the list, under Device Name or similar labels on other distributions.

How to change hostname in Linux Picture 1How to change hostname in Linux Picture 1

It's not immediately obvious, but you can click the Device Name entry and a dialog box will appear, allowing you to rename your device. Just enter whatever name you want to use in the dialog box and then click Rename.

How to change hostname in Linux Picture 2How to change hostname in Linux Picture 2

The new hostname will be permanently set and your computer will identify itself on the network with the new name.

Change hostname using Linux Terminal

The options that appear in the system settings depend on the desktop environment you are using. The process described above should work with Ubuntu's default GNOME desktop. However, if you have switched your desktop environment or window manager, you may not have the option to change the hostname in the system settings.

If that's the case, you can change your hostname by opening a command line window and entering a simple command.

The hostnamectl command will allow you to view and change the hostname on most other Linux distributions. Just open a command line window and enter the following command to see the current hostname along with some related details:

hostnamectl

Output:

How to change hostname in Linux Picture 3How to change hostname in Linux Picture 3

To change the hostname, enter the following command, replacing the new hostname with the name you want to use:

hostnamectl set-hostname new-hostname

To verify that the new name has been set, enter the hostname again and you should see the updated information.

Again, the command line method to change the Linux hostname should work on nearly all modern Linux distributions, not just Ubuntu.

Hope you are succesful.

4.5 ★ | 2 Vote

Maybe you are interested