🌐 🇵🇱 Polski · 🇬🇧 EN
Since June 10, 2014, we have had access to version 7 of the RedHat Linux system, and the CentOS system released a month later. In this version, we are dealing with a change in the system and service manager, which is now systemd (official project website). Introducing this solution requires changing habits from previous versions to new ones. Although we are dealing with a modified command syntax, using systemd is not particularly difficult. To start, we will perform a hostname change on Linux systems version 7. There are several ways to accomplish this simple task. Below are a few of them.
Temporary (until reboot) hostname change.
In this case, there are no changes, and we perform it with the command:
# hostname server1.example.com
# hostname
server1.example.com
Permanent hostname change.
One method is to manually enter the chosen name into the /etc/hostname file:
# echo server1.example.com > /etc/hostname
# reboot
After a reboot, the hostname has been changed (verification):
# hostname
server1.example.com
After rebooting and logging in, you can see the new hostname immediately after the username and the @ sign
[root@server1 ~]#
Using hostnamectl.
In version 7, we have the hostnamectl tool at our disposal. This tool offers the following capabilities:
# hostnamectl --help
hostnamectl [OPTIONS...] COMMAND ...
Query or change system hostname.
-h --help Show this help
--version Show package version
--transient Only set transient hostname
--static Only set static hostname
--pretty Only set pretty hostname
-P --privileged Acquire privileges before execution
--no-ask-password Do not prompt for password
-H --host=[USER@]HOST Operate on remote host
Commands:
status Show current hostname settings
set-hostname NAME Set system hostname
set-icon-name NAME Set icon name for host
set-chassis NAME Set chassis type for host
For the purposes of this post, we are interested in those related to changing the hostname, which we can do by typing:
# hostnamectl set-hostname server1_new_name
Verifying the changes:
# hostname
server1_new_name
Another way to verify (more information)
# hostnamectl
Static hostname: server1_new_name
Icon name: computer
Chassis: n/a
Machine ID: e25d2d5778334d39a8885cb602edeba9
Boot ID: 03afc345c926493ca1526abe0383c58e
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-229.el7.x86_64
Architecture: x86_64
With the second method, we also learn the system architecture and the kernel version.
Using Network Manager TUI to change the hostname.
If you want to change the hostname using a graphical interface, you can use the "nmtui" network configuration manager, where you can enter a new hostname using a wizard.
Invoking NetworkManager: # nmtui
![]() |
| NetworkManager panel - nmtui |
![]() |
| Hostname configuration using nmtui |
![]() |
| nmtui - hostname change confirmation |
Verifying the changes:
# hostname
server1.example.com




Comments