The hostname is set at the time when a Linux OS is installed by the respective installer (set-up scripts) on a bare-metal server or virtual machine.
Historically to change the hostname in most GNU / Lonux distributions (Debian / Ubuntu / Fedora / CentOS etc.) it was as easy as:
1. Getting your current setting for hostname with hostname command
hipo@jeremiah:~$ hostname –fqdn
2 Logging to the remote machine via ssh.
3. Editting /etc/hosts and substituting with the new desired hostname
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
5. Run command
and logout and login again to the host to make the new hostname active for the ssh session
Since around 2015 a new way was introduced to change hostname in Ubuntu 13.04 onwards and Fedora 21 and Debian 8 / 9 the way to set a new hostname comes again up to editting
and running command:
hostnamectl set-hostname your-new-desired-hostname
On Redhat based Linux distributions and Red Hat Enterprise Linux to change the hostname you will also need to edit:
Another universal way to edit hostname on any Linux distribution is to use sysctl cmd like so: