One of basics things you should be able to do after installing a Centos 7 or RHEL 7 is to know to change your hosname of your server. In this quick tutorial i’m gonna explain how to change the hostname on your CentOS 7 / RHEL 7 Linux server using four methods .
1. nmtui Tool ( Network Configuration Using a Text User Interface)
2. nmcli Tool ( NetworkManager Command Line )
3. hostnamectl Tool
4. Editing /etc/hostname
Before starting let’s check current hostname of our Centos 7 / RHEL 7 server :
[[email protected] ~]# hostname server
1./ nmtui tool:
The nmtui Tool ( Network Configuration Using a Text User Interface) is used to set a static host name in /etc/hostname .
Set the hostname and click ok.
Here we need to restart the hostnamed to apply the hostname changing.
[[email protected] ~]# systemctl restart systemd-hostnamed
2./ nmcli tool:
Let’s check the current hostname
[[email protected] ~]# nmcli general hostname server
Now change the host name.
[[email protected] ~]# nmcli general hostname client.yallalabs.com
Restart the hostnamed to make sure the change takes effect.
[[email protected] ~]# systemctl restart systemd-hostnamed
3./ hostnamectl tool:
When we use hostnamectl tool to change the host name of our server, it’s not required to restart the hostnamed or to reboot the server to ensure the change takes an effect.
Let’s check the current host name.
[[email protected] ~]# hostnamectl status Static hostname: server Icon name: computer-vm Chassis: vm Machine ID: 63e2c28ecd6348a3a956f74fc02f6d84 Boot ID: 840a0e1bc90b4ac3974bb5b5cc0b20cc Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64
Let’s change it.
[[email protected] ~]# hostnamectl set-hostname client.yallalabs.com
Let’s check if changes takes effects.
[[email protected] ~]# hostnamectl status Static hostname: client.yallalabs.com Icon name: computer-vm Chassis: vm Machine ID: 63e2c28ecd6348a3a956f74fc02f6d84 Boot ID: 840a0e1bc90b4ac3974bb5b5cc0b20cc Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-327.el7.x86_64 Architecture: x86-64
4./ Edit /etc/hostname:
[[email protected] ~]# vi /etc/hostname
Here like i mentioned before we need to restart hostnamed.
[[email protected] ~]# systemctl restart systemd-hostnamed
That’s it for now.