How to Change Hostname on CentOS 7.0/RHEL 7.0

Share this Article :

Q. I have CentOS 7.0 virtual private server, but the default hostname still localhost.localdomain. How do i change the hostname to my prefer hostname or FQDN ?

[[email protected] ~]# hostname

A. There are four(4) method to change the hostname on CentOS 7.0/RHEL 7.0.

Method 1
1. Login to your VPS as a root.
2. Type hostname followed by the new hostname.

As example :

[[email protected] ~]# hostname mynewhostname.local
[[email protected] ~]# hostname

Note : But the following changes will be lost after reboot.

Also Read :   How to Reset CentOS root Password

Method 2
1. Login to your VPS as a root.
2. Use hostnamectl set-hostname command to change the current hostname :

As example :

[[email protected] ~]# hostnamectl set-hostname

3. Restart the systemd-hostnamed daemon to reflect the changes permanently :

[[email protected] ~]# systemctl restart systemd-hostnamed

4. Check the new hostname :

[[email protected] ~]# hostnamectl status
   Static hostname:
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 72863e389b584a4dab36fae7f3bffda2
           Boot ID: 1cf2f4b5478649549916c0a5bd5d2414
    Virtualization: xen
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.15.4-x86_64-linode45
      Architecture: x86_64

Method 3
1. Login to your VPS as a root.
2. Modify /etc/hostname using your favourite text editor replace localhost.localdomain to your most prefered hostname or FQDN:

[[email protected] ~]# vi /etc/hostname

Edit to the following as example :

3. Try to login again by opening another putty session :

[[email protected] ~]# hostname

Method 4
1. Login to your VPS as a root.
2. Type nmtui in the terminal:

[[email protected] ~]# nmtui

3. Text user interface will appear :
centos7-change hostname1

Also Read :   How to Copy and Paste Text in one line With vi or vim in Linux

4. Using the arrow keys select Set system hostname and use tab to select OK.
centos7-change hostname2

5. Confirmation message will appear, Press OK to complete.

Leave a Reply