How to Change Hostname on CentOS 7.0/RHEL 7.0

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 ?

[root@localhost ~]# hostname
localhost.localdomain

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 :

[root@localhost ~]# hostname mynewhostname.local
[root@localhost ~]# hostname
mynewhostname.local

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

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

See also  How to install Bind DNS server on CentOS and RHEL

As example :

[root@localhost ~]# hostnamectl set-hostname ns1.e-coupondeals.com

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

[root@localhost ~]# systemctl restart systemd-hostnamed

4. Check the new hostname :

[root@localhost ~]# hostnamectl status
   Static hostname: ns1.e-coupondeals.com
         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:

[root@ns1 ~]# vi /etc/hostname

Edit to the following as example :

ns1.e-coupondeals.com

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

[root@ns1 ~]# hostname
ns1.e-coupondeals.com

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

[root@ns1 ~]# nmtui

3. Text user interface will appear :

See also  How to Check Memory Usage In Linux

4. Using the arrow keys select Set system hostname and use tab to select OK.

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

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

Leave a Reply

Your email address will not be published. Required fields are marked *