Hostname changes in 4 different ways


Method 1

We have been using this way for most of the Linux versions & it works fine in CentOS/RHEL 7 as well. In this way, we will manually add hostname by editing /etc/sysconfig/network,

$ vi /etc/sysconfig/network

and add your hostname,

NETWORKING=yes
HOSTNAME=centos7.linux.com

Restart network services to implement the changes.

$ systemctl restart network

You can now view the new hostname using command ‘hostname’.



Method 2

Second way for changing hostname is by using command ‘hostnamectl’. Hostnamectl is used to change or query hostname. For changing hostname, run the following command

$ hostnamectl set-hostname “centos7.linux.com”

To view the changes hostname, only run ‘hostnameclt‘ command,

$ hostnamectl

hostnamectl

If you completely want to remove the hostname, use ‘hostnamectl set-hostname “” ‘. This remove the hostname completely.

Method 3

Third method to change the hostname is not a preferred way but none the less it gets the job done. To view the current hostname ,
$ sysctl kernel.hostname
& if you want to change the hostname, run
$ sysctl kernel.hostname=centos7.linux.com
hostnamectl
Changes to the hostname will be immediate & you can verify the new hostname by running any of the above commands to check hostname.

Method 4

Its very simple to modify the hostname

But its temporary changes in the hostname

vi /etc/hosts


Comments

Popular posts from this blog

How To Know Which Program To Use To Open An Unknown File Extension

Step By Step: Install and Configure Sensu + Grafana

Hosting a WordPress Blog with Amazon Linux