Changing Hostname on Linux

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.

  1. Edit file /etc/hosts
  2. Edit file /etc/hostname (For RHEL7)
  3. Edit file /etc/sysconfig/network (For RHEL5, RHEL6)
  4. Execute the command hostname
  5. If you are using samba, you may also want to edit the samba configuration file at /etc/samba/smb.conf

For CentOS7

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.

Finally

I would suggest restarting the server to avoid trouble. As mentioned in that article, sendmail will not function properly without restart the sendmail.

Changelog

Edit 2016-05-30: Updated for RHEL7 with use of hostnamectl.

Edit 2015-06-22: Updated for RHEL7.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s