On Linux, hostname file is located in
/etc/hostname. We can change the hostname by editing this file. To edit the hostname using vim, run the following command:
sudo vim /etc/hostname
(Optional) You can edit the
/etc/hosts and add your hostname.
sudo vim /etc/hostsAdd the following line to your hosts file. Rename text in red with your hostname.
Now we have to restart the server for the server to use the new hostname: