In CentOS or RHEL, there are three kinds of hostnames defined: (1) static, (2) transient, and (3) pretty. The "static" hostname is also known as kernel hostname, which is initialized from /etc/hostname automatically at boot time. The "transient" hostname is a temporary hostname assigned at run time, for example, by a DHCP or mDNS server. Both static and transient hostnames follow the same character restriction rules as Internet domain names. On the other hand, the "pretty" hostname is allowed to have a free-form (including special/whitespace characters) hostname, presented to end users (e.g., Dan's Computer).
In CentOS/RHEL 7, there is a command line utility called hostnamectl, which allows you to view or modify hostname related configurations.
To view hostname related settings:
To view static, transient or pretty hostname only, use "--static", "--transient" or "--pretty" option, respectively.
To change all three hostnames: static, transient, and pretty, simultaneously:
As shown above, in case of static/transient hostnames, any special or whitespace character will be removed, and any uppercase letter will automatically be converted to lowercase in the supplied <host-name> argument. Once the static hostname is changed, /etc/hostname will automatically be updated accordingly. However, /etc/hosts will not be updated to reflect the change, so you need to update /etc/hosts manually.
If you want to change a particular hostname only (static, transient or pretty), you can use "--static", "--transient" or "--pretty" option.
For example, to change hostname permanently, you can change the static hostname:
Note that you do not have to reboot the machine to activate permanent hostname change. The above command will change kernel hostname immediately. Log out, and log back in to see the new static hostname in the command-line prompt.
Final note: the official recommendation by Red Hat is that both static and transient names of a host match the FQDN (fully-qualified domain name) of the host (e.g., myhost.xmodulo.com). FQDN is always preferred to avoid any confusion in host naming in any kind of service deployment. Thus, if a host is assigned by DNS myhost.xmodulo.com as its FQDN, use the same FQDN as its hostname:
Subscribe to Ask Xmodulo
Do you want to receive Linux related questions & answers published at Ask Xmodulo? Enter your email address below, and we will deliver our Linux Q&A straight to your email box, for free. Delivery powered by Google Feedburner.
Did you find this tutorial helpful? Then please be generous and support Xmodulo!