Centos Linux Permanently Change Hostname

This post will guide you how to change the hostname for a Centos Linux system permanently. You will learn that how to use the hostnamectl command to change hostname. Or how to use nmtui command and nmcli command to change hostname.

You can use any one of the following methods to change the hostname on Centos Linux operation system.

Method 1: Change HostName using Hostnamectl command

To check the current hostname, just type the following command:

#hostnamectl

Or

# hostnamectl status

Outputs:

[root@localhost ~]# hostnamectl
   Static hostname: localhost.localdomain
         Icon name: computer
           Chassis: n/a
        Machine ID: 5ccdf457288947d38a7bdbe2ad38dca1
           Boot ID: d90c5b87825d416fa0ac6eebd144ede0
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64

To set the hostname as “devops”, just run the following command:

#hostnamectl set-hostname devops

Outputs:

[root@localhost ~]# hostnamectl set-hostname devops

[root@localhost ~]# hostnamectl status
   Static hostname: devops
         Icon name: computer
           Chassis: n/a
        Machine ID: 5ccdf457288947d38a7bdbe2ad38dca1
           Boot ID: d90c5b87825d416fa0ac6eebd144ede0
    Virtualization: oracle
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64

Method2: Change hostname using nmtui tool

You can also set hostname using nmtui tool in the command line of Centos Linux.

Type the below command:

#nmtui

Press TAB key to switch to Set system hostname, press enter key.

centos nmtui1

Then type the hostname as you need.

centos nmtui2

centos nmtui3

Method3: Change hostname using nmcli tool

You can also set hostname using nmcli tool in the command line of Centos Linux.

You can use nmcli tool to check the current hostname, just type the following command:

#nmcli general hostname

Outputs:

[root@localhost ~]# nmcli general hostname
devops

If you want to set the hostname as you need, just type the following command:

#nmcli general hostname devops

Then restart the system-hostnamed service, type:

#systemctl restart systemd-hostnamed

Outputs:

[root@localhost ~]# nmcli general hostname devops
[root@localhost ~]# systemctl restart systemd-hostnamed
[root@localhost ~]# nmcli general hostname
devops

 

You might also like:

Sidebar



back to top