Generally, a hostname is just an assigned name to a computer, laptop, or any other connected device to a network. You can say a hostname is a computer’s nickname, and it is used to identify the machine over the network uniquely.
Sometimes you need to name your computer with a new hostname so it would be easy to recognize it. It is highly recommended not to name two computers on the same network with the same hostname because this would result in a conflict in the network causing issues. The hostname is used to uniquely identify your computer over a network.
In this tutorial, we are going to walk you through changing your Ubuntu machine’s hostname. There are several ways to do it, and we are going to discuss all of them.
Changing your Ubuntu System’s Hostname
We shall look at the command line as well as GUI methods.
Check Computer’s Current Hostname
Before we can start, you can check the current hostname using the following command in the terminal.
As you can notice, my computer’s current hostname is FOSSLinux. In the next few steps, we are going to change this to a new one.
Change Hostname via Command Line
In this section, you will learn how to change your machine hostname using the command line method using the terminal. There are multiple commands you can use, such as:
- hostname command
- hostnamectl command
Change Computer’s Hostname Using hostname Command
Using this method, you will be able to change your computer hostname permanently without even needing to reboot the system.
Step 1. Launch the terminal using this shortcut keys Ctrl + ALT+ T.
Step 2. Use the following hostname command with your the new hostname you need:
sudo hostname FossLinux1
Step 3. Open the hostname configuration file using your favorite editor.
sudo vi /etc/hostname
Step 4. Edit the hostname configuration file and add the new hostname:
Step 5. Open the “hosts” configuration file using your favorite editor.
sudo vi /etc/hosts
Now you need to ensure that you have commented on all the old hostnames using the “#” symbol. Then add the new hostname as follows:
Step 6. Go and check your hostname now.
Change Computer’s Hostname Using hostnamectl Command
Step 1. Check the current computer hostname using the command:
As you can observe, the current computer’s name is FossLinux1, and we are going to change this.
Step 2. Use the hostnamectl to set your computer’s name.
sudo hostnamectl set-hostname FossLinux2
Step3. Edit the /etc/hosts file using your favorite editor.
sudo vi /etc/hosts
Ensure you have commented out the old hostname and add your new hostname as follows:
Step 4. Check your current hostname.
Change Hostname Via Graphical User Interface
The easiest method for changing your computer hostname is through the system graphical settings menu.
Step 1. Open the drop-down arrow from the top of the screen.
Step 2. Select the settings button.
Step 3. From the left menu, select the Details menu.
Step 4. Next, open the About option.
Step 5. From the right side, you will find your computer’s information. The hostname can be found under the device name.
Step 6. Easily you can change the device hostname to a new one.
Step 7. Reboot your system.
Step 8. Check your current hostname.
Congratulations; you have just learned how to change your computer’s hostname using various methods. That’s it!