1. How To Change Hostname in CentOS 7
i | P a g e
Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Different Methods ........................................................................................................................................1
Get Hostname – localhost.localdomain........................................................................................................1
Set Hostname................................................................................................................................................2
Get Hostname – New....................................................................................................................................2
Restart Service – system-hostnamed ...........................................................................................................3
Get Hostname – hostnamectl.......................................................................................................................3
Reboot Server ...............................................................................................................................................4
2. How To Change Hostname in CentOS 7
1 | P a g e
Overview
The purpose of this guide is the modify / set hostname in CentOS 7 operating system. We have multiple
methods of changing hostname of the server, in this guide we will focus on nmcli tool.
Applies To
CentOS 7.
Different Methods
We can change hostname in 4 ways
1) nmcli Tool
2) hostnamectl
3) nmtui Tool
4) edit /etc/hosts file
Get Hostname – localhost.localdomain
By Default, when you install the Operating system when the installation process is unable to resolve the
IP address, you’re hostname would be defined as “localhost” and FQDN hostname would be defined as
“localhost.localdomain”. To know the current hostname set run the either of the below command(s).
hostname
nmcli general hostname
3. How To Change Hostname in CentOS 7
2 | P a g e
Set Hostname
To set new or update hostname run the command.
nmcli general hostname vcptest.effonetech.com
Get Hostname – New
Re-run the command hostname to know the hostname set after modifying to new name.
hostname
4. How To Change Hostname in CentOS 7
3 | P a g e
Restart Service – system-hostnamed
Restart the daemon “system-hostnamed” to make modifications permanent.
systemctl restart system-hostnamed
Get Hostname – hostnamectl
Re-run the command “hostnamectl” to know static hostname information of the server.
hostnamectl
5. How To Change Hostname in CentOS 7
4 | P a g e
Reboot Server
Reboot the server, run the command “reboot”. After rebooting the server the hostname that’s set is
permanent.
reboot