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.
127.0.0.1 hostnameNow we have to restart the server for the server to use the new hostname: