Introduction : For CentOS 8 you can use the hostnamectl command to change the hostname of a CentOS 8 server, laptop or desktop. You can use the hostname command to see or set the system’s hostname too. The hostname or computer name is usually at system startup in /etc/hostname file. Open the terminal application and type the following command to change the hostname on CentOS 8.
Display the current CentOS 8 hostname
Type any one of the following command:
$ hostname
OR
$ hostnamectl
CentOS 8 change hostname command
The procedure to change the computer name on CentOS Linux:
- Type the following command to edit /etc/hostname using nano or vi text editor:
sudo vi /etc/hostname - Delete the old name and setup new name.
- Next Edit the /etc/hosts file:
sudo vi /etc/hosts - Replace any occurrence of the existing computer name with your new one.
- Reboot the system to changes take effect:
sudo reboot
How to change the CentOS 8 server hostname without a system restart
Type the following commands:
$ sudo hostname nixcraft-centos8
Next edit the /etc/hostname file and update hostname:
$ sudo vi /etc/hostname
Finally, edit the /etc/hosts file and update the lines that reads your old-host-name:
$ sudo vi /etc/hosts
From:
127.0.1.1 localhost
To:
127.0.1.1 nixcraft-centos8
Save and close the file.
A note about hostnamectl command
Systemd based Linux distributions such as CentOS 8 can simply use the hostnamectl command to rename hostname. To see current setting just type:
$ hostnamectl
Sample outputs:
Static hostname: localhost.localdomain Transient hostname: li2025-143.members.linode.com Icon name: computer-vm Chassis: vm Machine ID: 3e729c2d7c094902af0333ce40564ffe Boot ID: e359e65f68ff45f2825134354bdc0a8d Virtualization: kvm Operating System: CentOS Linux 8 (Core) CPE OS Name: cpe:/o:centos:centos:8 Kernel: Linux 4.18.0-80.7.1.el8_0.x86_64 Architecture: x86-64
To change hostname from localhost.localdomain to nixcraft-centos8, enter:
$ sudo hostnamectl set-hostname nixcraft-centos8
$ hostnamectl
Set or change CentOS 8 server hostname using the hostnamectl command
Conclusion
On CentOS 8 one can use the hostnamectl command to control the system hostname and set a new name as well. This is recommended method for all CentOS 8 users.
- Ubuntu Linux Change Hostname (computer name)
- Debian Linux: Change Hostname / Computer Name Permanently
- Linux change my hostname / computer system name
- Linux Change Hostname
- RHEL / Centos Linux 7: Change and Set Hostname Command
- OpenBSD Change Hostname
- CentOS Linux 5/6 Change Hostname Command
- Linux setting hostname and domain name of my server
- FreeBSD Change Hostname without reboot
- SuSe Linux Change Hostname without reboot
- How to set the hostname on Fedora Linux
- Ubuntu 18.04 LTS change hostname permanently
- Ubuntu set hostname permanently (computer name) command
- OpenSUSE Linux set hostname permanently (computer name) command
- RHEL 8 Linux set hostname permanently (computer name) command
- CentOS 8 Linux set hostname permanently (computer name) command
- Ubuntu 20.04 LTS set hostname permanently (computer name) command
- Set / Change FQDN on Ubuntu 20.04 LTS
- Alpine Linux - Setting system hostname
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 0 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |