HOSTNAME ON REDHAT 7

CHANGE HOSTNAME IN REDHAT 7 /CENTOS 7

In this guide, We are going to learn how to modify hostname in different ways on Redhat 7.

1.hostnamectl method –> Most recommended method.

2.nmtui command –> using the text user interface.

3.nmcli command –> using CLI of Network Manager.

Types of Hostname

  • Static Hostname –> Hostname assigned by sysadmin/ user and stored in /etc/hostname
  • Dynamic/Transient Hostname –> This hostname is maintained by kernel and its changed by DNS/mDNS
  • Pretty Hostname –> It’s in the form of UTF-8 for presentation to the user.

Hostname can be Created with

  • 64 characters in length
  • FQDN (Fully Qualified Domain Name) is Recommended.
  • Can contain “a-z” “A-Z” “0-9” “.” “_” “-“

Before proceeding, Let us check the hostname using the command:

#hostname

You will see something like this

 

 

Method 1 – nmtui Tool

Network Manager tool is used to change the static hostname in /etc/hostname file.Just type nmtui and Enter.You will see the following screen.

#nmtui

 

 

 

 

 

 

 

 

 

Choose Set system hostname

 

 

 

 

 

 

 

 

set the hostname [FQDN] as shown below, and OK.

 

 

 

 

 

 

 

 

Now, We need to restart hostnamed service to force hostnamectl to notice the change of static hostname.

#systemctl restart systemd-hostnamed

You can verify using hostname command.

 

 

 

Method 2 – hostnamectl

We can change the hostname using the hostnamectl command.

Check the current hostname using the command:

#hostnamectl status

 

 

 

 

 

 

You can set the hostname using the below command:

#hostnamectl set-hostname rahul.linuxcloudops.com

check the status now,

#hostnamectl status

 

 

 

 

 

 

 

Method 3 – nmcli Command

It is used to query and set static hostname in /etc/hostname file

Initially, Check the hostname:

#nmcli general hostname

 

 

To change the hostname use the command:

#nmcli general hostname rahul.devops.com and Restart the service

#systemctl restart systemd-hostnamed

 

 

 

Method 4

This is the very simple method, But it requires a system reboot.

You have to edit /etc/hostname file to change the hostname.

Note

You are always recommended to use the hostnamectl command to change the hostname whenever required which doesn’t require the kernel update to make the hostname changes effect.

That’s All.Thanks for reading this article.Hope it helped you a lot.