Solved: How to change hostname using nmtui or nmcli in redhat linux

In our last post we have seen how to change hostname manually or with hostnamectl .

In this post we will discuss how to change hostname with nmtui and nmcli tools.

nmtui

Let’s first try with nmtui tool

  • If you don’t have the nmtui tool installed, you can install it using yum
yum install NetworkManager-tui
  • Invoke the nmtui interface from the command line by executing as root user
nmtui
  • In the menu select “Set system hostname” as shown below

  • Write the new hostname which you want to keep.  We want to change it to “prodvedas”.

  • To make it effective restart the “hostnamed” service
systemctl restart systemd-hostnamed
  • Now if you login with new session or do “su -” in same session you should see new hostname.

nmcli

Let’s try changing the hostname with nmcli tool in Redhat Linux.

  • To check the current hostname
nmcli general hostname
  • If you want to change the hostname
nmcli general hostname prodvedas
  • To make it effective restart hostnamed service
systemctl restart systemd-hostnamed
  • Now if you login with new session or do “su -” in same session you should see new hostname.

Hostname changed by any of the above method will be persistent across reboot.

If you are trying to change hostname of AWS EC2 linux instance the process will be slightly different. Refer this post to change AWS EC2 instance hostname.

Refer this post to change IP using nmtui and nmcli.

Solved: How to change hostname in Redhat Linux

In this post we will see how to change hostname in Redhat Linux 4, 5, 6 and 7 .

For changing the hostname you should have root access. To switch to root do:-

sudo su -

If you want to change the hostname temporarily do as below:-

hostname <new-hostname>
e.g.
hostname cloudvedas

But above change is not permanent and will change back to old name after reboot.

To make the change permanent you will have to make the entry in couple of files. If you are using RHEL 4,5,6 use the below steps, else directly go down to section for RHEL 7. If you don’t want to modify files manually refer this post to change hostname using nmtui or nmcli tools.

RedHat based system use the file /etc/sysconfig/network to read the saved hostname at system boot.

NETWORKING=yes
HOSTNAME=cloudvedas

Next you have to modify /etc/hosts file. Entry in hosts file should look like.

172.25.31.65 cloudvedas

RHEL 7

If you are having RHEL 7 you just have to execute one command which will take care of everything.

hostnamectl set-hostname --static cloudvedas

The above steps will make the hostname change persistent across reboot.

If you want, try to reboot the server with command “reboot” .

Once the server is up, check the hostname.

root# hostname
cloudvedas
root#

It should now show you the new hostname.

If you are using RHEL AMI from AWS marketplace the steps will be slightly different. For that refer our other post How to change hostname in AWS EC2 instance of RHEL 7 .