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

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

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 :

READ  Nginx Released Version Nginx 1.6.3

As example :

[root@localhost ~]# hostnamectl set-hostname

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:
         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 :

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

[root@ns1 ~]# hostname

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 :
centos7-change hostname1

READ  How to Install phpMyAdmin on CentOS 6/7 / RHEL 6/7

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

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>