I came across one scenario where I need to change the hostname of the server. So I accomplished the task by performing below steps.
I need to change Linux hostname from test.example.com to testapps.example.com.
1. Check the current hostname.
[root@test ~]# hostnamectl status
Static hostname: test.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: ef19bcc0dc411a489586b40491880731
Boot ID: 4f5eafda9648487295655674d574d6d9
Virtualization: kvm
Operating System: Oracle Linux Server 7.9
CPE OS Name: cpe:/o:oracle:linux:7:9:server
Kernel: Linux 5.4.17-2102.201.3.el7uek.x86_64
Architecture: x86-642. Change the hostname.
On Linux systems that support hostnamectl (such as RHEL 7/8/9), execute:
[root@test ~]# sudo hostnamectl set-hostname testapps.example.com
[root@test ~]#
[root@test ~]# hostnamectl status
Static hostname: testapps.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: ef19bcc0dc411a489586b40491880731
Boot ID: 4f5eafda9648487295655674d574d6d9
Virtualization: kvm
Operating System: Oracle Linux Server 7.9
CPE OS Name: cpe:/o:oracle:linux:7:9:server
Kernel: Linux 5.4.17-2102.201.3.el7uek.x86_64
Architecture: x86-643. Verify the change.
[root@test ~]# hostname
testapps.example.com
[root@test ~]# hostname -f
testapps.example.comHappy Learning ! 🙂
Disclaimer:
This is an independent personal blog and is not affiliated with, sponsored by, or endorsed by Oracle Corporation. The views, explanations, and experiences expressed here are the author’s own. Commands, scripts, and procedures may be based on Oracle’s official documentation and are provided for educational and reference purposes only. Always test and validate them before use in a Live/Production environment. Sample output shown in this article was generated during the author’s own testing and may vary depending on the environment.
Please read full Disclaimer.
