Wednesday, July 30, 2008

Changing hostname on RHEL

To change the hostname in RHEL and other versions of Linux you need to make changes in a couple of files.

  • Change the HOSTNAME line in /etc/sysconfig/network

NETWORKING=yes

HOSTNAME="mybox.mydomain.com"

  • Change the hostname (FQDN and alias) in /etc/hosts

If your IP address is assigned to you by a DHCP server, then:

127.0.0.1 mybox.mydomain.com localhost.localdomain localhost mybox

If you have a static IP address, then:

127.0.0.1 localhost.localdomain localhost

192.168.0.10 mybox.mydomain.com mybox

  • Run /bin/hostname <new_hostname> for the hostname change to take effect immediately.
  • Run /sbin/service syslog restart for syslog to log using the new hostname.
  • To update the local DNS server, that supports dynamic registration of hostname record, with your host name and DHCP IP address add the following line to the correct ifcfg file in /etc/sysconfig/network-scripts, such as ifcfg-eth0 or ifcfg-eth1:

DHCP_HOSTNAME="mybox.mydomain.com"

  • Updated information the PTR record in ddns:

Kill the dhclient process ("killall dhclient") - make sure it is gone

Then restart networking - "service network restart"

A reboot is not required to change the system hostname.

-------------- End of Document -----------------

Tags: RHEL, General Administration

Published Date: 20080730