Changing hostname in Linux
Changing hostname in Linux
Background
Before the invention of DNS, your computer’s hostname was managed through the HOSTS file located at /etc/hosts. Anytime that a new computer was connected to your local network, all other computers on the network needed to add the new machine into the /etc/hosts file in order to communicate over the network.
Hostnames are the designations by which we separate systems into easily recognizable assets.
This is optional, but we can check the current status: Show current system hostname and related information.
1
hostnamectl status
Static hostname: hostname1
Icon name: computer-vm
Chassis: vm
Machine ID: XXXXXXXXXXXXXXXXXXXXXXXXXX
Boot ID: XXXXXXXXXXXXXXXXXXXXXXXXXX
Virtualization: kvm
Operating System: Red Hat Enterprise Linux 8.9 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
Kernel: Linux 4.18.0-513.24.1.el8_9.x86_64
Architecture: x86-64
Then we can set the new hostname:
1
hostnamectl set-hostname hostname2
and then we check the status:
1
hostnamectl status
Static hostname: hostname2
Icon name: computer-vm
Chassis: vm
Machine ID: XXXXXXXXXXXXXXXXXXXXXXXXXX
Boot ID: XXXXXXXXXXXXXXXXXXXXXXXXXX
Virtualization: kvm
Operating System: Red Hat Enterprise Linux 8.9 (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8::baseos
Kernel: Linux 4.18.0-513.24.1.el8_9.x86_64
Architecture: x86-64
Reboot the server.
1
reboot
ssh again and check the new hostname!
1
hostname
Sources
Photo by Djim Loic on Unsplash
How to change your hostname in Linux https://www.redhat.com/sysadmin/change-hostname-linux
Want to thank me?
🤝 Buy me a coffee https://buymeacoffee.com/dbplatz
This post is licensed under CC BY 4.0 by the author.