Changing hostname on Linux seems to be an easy task but in fact it is easy to miss the place that required changes. Depends on which Linux you use, the method may varies:
For RHEL5 and RHEL6
According to this article, here are some files and 1 command that needs to be edited and executed.
- Edit file /etc/hosts
Edit file /etc/hostname (For RHEL7)
- Edit file /etc/sysconfig/network (For RHEL5, RHEL6)
- Execute the command hostname
- If you are using samba, you may also want to edit the samba configuration file at /etc/samba/smb.conf
Actually there is a command called hostnamectl which you can use to change the hostname. I didn’t have the environment to test it. You may also need to edit some of the configuration file mentioned above to make it fully working.
I would suggest restarting the server to avoid trouble. As mentioned in that article, sendmail will not function properly without restart the sendmail.
Edit 2016-05-30: Updated for RHEL7 with use of hostnamectl.
Edit 2015-06-22: Updated for RHEL7.