I've seen a few ways of changing hostnames of domain names.One way is to issue the hostname command followed by the name such as:hostname localhost.localdomain/etc/sysconfig/network also has a hostname field, but changing that does not affect the output of the hostname command.My question is, where is each of these used, which do I care about and why? What's the proper way of setting the hostname?
What is the foolproof/proper way to set hostname and domain on CentOS
networking;centos;rhel
If you set your hostname in /etc/sysconfig/network then the system will automatically set your hostname for you every time you boot.This magic is done in /etc/rc.d/rc.sysinit. It does this using the hostname command in the third line below:-# Set the hostname.update_boot_stage RChostnameaction $Setting hostname ${HOSTNAME}:  hostname ${HOSTNAME}[ -n ${NISDOMAIN} ] && domainname ${NISDOMAIN}The variable HOSTNAME is defined in /etc/sysconfig/network.If you set it manually using the hostname command, then it will not be persistent over a re-boot.