How to Change the Hostname on an Ubuntu 22.04 VPS or Dedicated Server | HostAdvice

How to Change the Hostname on an Ubuntu 22.04 VPS or Dedicated Server

Ubuntu 22.04 was launched on April 21, 2022. The final release of Ubuntu 22.04 is available and that means everyone can start using it even on production servers. Ubuntu 22.04 has many improvements including faster boot times and bug fixes.

Just like with a brand new computer, setting an Ubuntu 22.04 hostname is a pivotal process. This might sound tricky when it comes to provisioning your VPS server for the first time. Some people might not care about the Linux’s hostname during the initial process. However, this can lead to a lot of confusion if an administrator is logging to different VPS instances.

A hostname should give quick relevant information about the system where one is logged in. This doesn’t come out of the box and most data centres and hosting company will really set some weird hostnames on new Ubuntu 22.04 instances.

A hostname is simply a label that is assigned to a device on a network to distinguish it from the rest of the devices. Or you might refer to the hostname as another name for “Computer Name“. Hostnames play an important role when it comes to resolving common easy to remember names to IP addresses through the DNS service.

You may use any hostname for your Ubuntu 22.04 server but most people name it after planets or even animals and others will pre-fix the location of the server on the name .e.g New_York_Pluto, Miami_proxima_b.

In this guide, I will show you how to change the name of your Ubuntu 22.04 server.

Prerequisites

  • An VPS server running Ubuntu 22.04
  • A non-root user with sudo privileges
Note
Special Note: Are you looking for a Linux hosting service? Find the best Linux hosting services including expert and user reviews on HostAdvice.

Step 1: Checking the default hostname

First, login to your terminal window and type the command below to get your current hostname.

 

$ hostname

or

$ hostnamectl

 

The command hostname will display your Ubuntu 22.04’s current hostname. If you use the second alternative hostnamectl, you will see a lot of information about your server as shown in the image below

How to Change the Hostname on an Ubuntu 22.04 VPS or Dedicated Server

Step 2: Changing the hostname

In Ubuntu 22.04, you will be required to edit two files to change your hostname. To edit the first file, type the command below on a terminal window:

$ sudo nano /etc/hostname

Editing the /etc/hostname

How to Change the Hostname on an Ubuntu 22.04 VPS or Dedicated Server

As seen above, the hostname will be displayed at the top of the file. You need to overwrite that value with your desired hostname. Then, press CTR+O to save changes and Ctrl+X to exit from this window.

Changing Ubuntu 22.04 server name on the hosts file

You will also need to edit the /etc/hosts file. To do this, type the command below on a terminal window:

$ sudo nano /etc/hosts

 

How to Change the Hostname on an Ubuntu 22.04 VPS or Dedicated Server

As seen above. The first line on the hosts file displays the localhost on the IP address 127.0.0.1. Leave that line intact. Then you will need to edit/add the hostname on the second line after the loop back IP address 127.0.1.1.  Also, you might find it necessary to reference your VPS hostname under your Ubuntu 22.04 server’s public IP address by adding a third line as show below.

127.0.0.1       localhost

127.0.1.1       Ubuntu-VirtualBox

x.x.x.x variety_village

Step 3: Reboot the system

In order for the changes to take place, you need to restart your Ubuntu 22.04 server. Type the command below

$ sudo reboot

Conclusion

That’s it; you have changed your Ubuntu 22.04 hostname. Remember you can always check if your hostname was changed successfully by typing the command ‘hostname’ one more time on the terminal window. If everything went as expected, you will be able to login on your Ubuntu VPS instance without any confusion.

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How To Set up a VSFTPD Server on an Ubuntu 16.04 VPS or Dedicated Server

Brief Description FTP data is usually insecure since information (usernames, pa
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to use phpMyAdmin to develop a website (without MySQL experience)

Brief description A web developer who is not well versed into coding websites f
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top