X
X

Select Your Currency

Türk Lirası $ US Dollar
X
X

Select Your Currency

Türk Lirası $ US Dollar

Knowledge Base

How to Change Hostname on Ubuntu Server?

In Ubuntu-based servers, the hostname plays a critical role in identification and management across the network. Changing the hostname is necessary to maintain organizational order, especially between multiple servers. This article explains how to change the hostname on an Ubuntu server step by step.

 

Temporarily Change the Hostname

 

To temporarily change the hostname, which will be effective until the server is restarted, use the following command:

sudo hostname new-hostname

This change will only be valid for the current session, and the hostname will revert to the old one once the server is rebooted.

 

Permanently Change the Hostname

 

To make a permanent hostname change, follow these steps:

  1. Update the Hostname File

    First, the old hostname in the /etc/hostname file should be removed, and the new hostname should be entered. This file determines the hostname used during system startup.

 

sudo nano /etc/hostname

 

  1. Update the Hosts File

    Next, the hosts file should be updated with the new hostname. This file contains information about how the server is identified within the local network. Making the necessary changes ensures proper communication with other devices on the network.

sudo nano /etc/hosts

 

For example, the line should be updated as follows:

127.0.1.1 new-hostname

 

  1. Change the Hostname Using Hostnamectl

    Finally, to permanently change the hostname, the hostnamectl command can be used. This command will update the hostname both temporarily and permanently across the system.

sudo hostnamectl set-hostname new-hostname

 

Reboot the Server to Apply Changes

 

To ensure the hostname changes are fully applied, the server needs to be rebooted. This ensures that all system components work correctly with the new hostname.

sudo reboot

After the reboot, the updated hostname can be checked with the following command:

hostnamectl

 

Changing the hostname on an Ubuntu server can be done easily by following the correct steps. Both temporary and permanent changes can be applied using the appropriate commands and file updates. This process is essential for maintaining management and organization across a network.

Did you find it useful?
(4 times viewed / 0 people found it helpful)

Can't find the information you are looking for?

Create a Support Ticket
Top