Thursday, 14 August 2025

Changing the hostname in Linux

(adsbygoogle = window.adsbygoogle || []).push({});
Changing the hostname in Linux depends on your distribution and whether you're using **systemd** (most modern distros do).

1. Check Current Hostname

[root@test ~]# hostnamectl status
   Static hostname: test.localdomain
         Icon name: computer-vm
           Chassis: vm
[root@test ~]# date
Thu Aug 14 15:53:54 +04 2025
[root@test ~]# uptime
 15:53:56 up 1 min,  1 user,  load average: 2.46, 0.70, 0.24
 
2. Change Hostname (Permanent)

Using `hostnamectl` (Recommended for systemd-based systems like Ubuntu, CentOS 7+, RHEL 7+, Debian 9+)

sudo hostnamectl set-hostname new-hostname
[root@test ~]# hostnamectl set-hostname muthu.org


> Replace `new-hostname` with your desired name.

3. Update `/etc/hosts`

Edit the file:

sudo nano /etc/hosts

[root@test ~] vi /etc/hosts

Find the line like:

127.0.1.1    old-hostname

And change it to:

127.0.1.1    new-hostname

This ensures local name resolution works properly.

4. Reboot or Re-login

Although the change is immediate, some services may require a reboot:
sudo reboot

[root@test ~]# reboot

Sample Text

Sample text