Changing Hostname In OEL7….

I am working on refreshing my set up with the latest version of database – Oracle 19c. In order to do so, I have made a new VBox vm with OEL 7.6 as the base operating system. One thing that I didn’t find in the installation(or may be I missed it completely) was to set up the hostname for the machine. Of course we can do so after the installation by editing the hostname file under the folder /etc. But I found a better way to do so and that’s using command HOSTNAMECTL. Here is what I did to change my hostname.

[aman@localhost ~]$ hostnamectl status
    Static hostname: localhost.localdomain
          Icon name: computer-vm
            Chassis: vm
         Machine ID: cc84beee53ce4747b2966c65bbda9a19
            Boot ID: 37cd3219ae58477d8a68e2a8f9d04ef6
     Virtualization: kvm
   Operating System: Oracle Linux Server 7.6
        CPE OS Name: cpe:/o:oracle:linux:7:6:server
             Kernel: Linux 4.14.35-1818.3.3.el7uek.x86_64
       Architecture: x86-64

As you can see the command returned the output with the hostname as Localhost. Now, let’s change it to something more meaningful .

[aman@localhost ~]$ hostnamectl set-hostname sandbox –static

And now, let’s check the output of the hostname command again.

[aman@localhost ~]$ hostname -f
sandbox

[aman@localhost ~]$ hostnamectl status
    Static hostname: sandbox
          Icon name: computer-vm
            Chassis: vm
         Machine ID: cc84beee53ce4747b2966c65bbda9a19
            Boot ID: 37cd3219ae58477d8a68e2a8f9d04ef6
     Virtualization: kvm
   Operating System: Oracle Linux Server 7.6
        CPE OS Name: cpe:/o:oracle:linux:7:6:server
             Kernel: Linux 4.14.35-1818.3.3.el7uek.x86_64
       Architecture: x86-64

And now, the hostname is changed to Sandbox-the same nam as what I gave to my VM in the installation also. Not only this, this command also updates the /etc/hostname also.

[aman@localhost ~]$ cat /etc/hostname
sandbox

Hope this helps.

Aman….