Tech Mitra

Technology News, Tutorials, How-to
How to Change Hostname on Ubuntu 22 Server

If you want to customize your Ubuntu 22.04 server hostname on your newly configured server it’s pretty easy. The hostname is the name that your computer uses to identify itself on the network. It is also the name that appears in your terminal prompt, internet address, email address, and other network-related settings. Changing the hostname can help you personalize your system and make it easier to recognize on the network.

In this blog post, we will show you how to change the hostname on Ubuntu 22.04 in a few easy steps. You will need to have administrative privileges (root access) to perform this task. You can use either the graphical user interface (GUI) or the command-line interface (CLI) to change the hostname. We will cover both methods in this guide.

Prerequisites to change Ubuntu Server Hostname

  • Access to the terminal window/ Command line via SSH
  • Root privileges on your user account

Step 1: First check your server current hostname

The first step in changing the hostname of your system is to check what the current hostname is. You can do this by opening a terminal window and running the following command:


Above output in terminal window will show the current hostname of your server

Step 2: Changing Ubuntu Server Hostname

You have learned how to check the current hostname of your system. Now you can modify it to a different hostname. To do this, you need to open a terminal window and enter the following command, where newhostname is the hostname you want to use:

hostname newhostname

Step 3: Update the Hosts File

Next what is left to update the hosts file, The /etc/hosts file is an important configuration file that maps hostnames to IP addresses. It helps the system to communicate with other devices on the network. To edit the /etc/hosts file, you need to use a text editor with root privileges. One way to do that is to run the following command in a terminal:

sudo nano /etc/hosts

Update the line to use the new hostname. For example, if your new hostname is myhost, the line should look like this: myhost

Save and close the file ( use Ctrl+w as we are using nano) when you make above changes.

Step 3: Now Reboot the System / Server

Finally as last step, you need to reboot your ubuntu server for the changes to take effect. To do this, type the following command:

sudo reboot

After reboot is complete login to your server using ssh via terminal and to check the new hostname type following command:


The output for above command will display the new hostname of your ubuntu server.


This post showed you how to modify the hostname on an Ubuntu 22 Server . You will first verify the current hostname, then modify the hostname, update the hosts file, and restart the server. These steps will help you to easily modify the hostname on an Ubuntu 22 Server.