How to change the hostname

Posted . Visible to the public.

Option 1 - with reboot

  1. Edit /etc/sysconfig/network.
  2. Edit /etc/hosts.
  3. Reboot.

Option 2 - without reboot

Edit /etc/sysconfig/network.

NETWORKING=yes
HOSTNAME=myhost.localdomain

Edit /etc/hosts to get proper resolving. Don't remove the localhost definitions!

127.0.0.1      localhost.localdomain localhost4.localdomain4 localhost4 localhost
::1            localhost.localdomain localhost6.localdomain6 localhost6 localhost
127.0.1.1      myhost.localdomain myhost

Notify the kernel about your new hostname.

hostname myhost.localdomain

Verify that the kernel is informed about the new hostname.

cat /proc/sys/kernel/hostname

Restart rsyslog.

service rsyslog restart

NOTE:

It is recommended to reboot the server after changing the hostname to prevent issues.

Last edit
cakuzo
Tags
Posted by cakuzo to redhat (2015-08-06 21:42)