How to Change or Set hostname on OEL/RHEL/CentOS 6

We can change the hostname of the Oracle Enterprise Linux (OEL), Red Hat Linux (RHEL) or CentOS version 6 operating system by using two basic methods which using the command line or graphical interface.

Warning: Changing the hostname on a system may have unexpected effects on running network services. It is best to shut down services like Oracle and web services before changing the hostname, or better yet, make the change to the appropriate configuration files, then reboot for the change to take effect.

How to find hostname?

Use the hostname command to find the hostname of the Linux system. For example:

# hostname
# grep -i hostname /etc/sysconfig/network

Set / Change the hostname via comand-line

  1. Using a text editor, open the servers /etc/sysconfig/network file.
    % sudo vi /etc/sysconfig/network
  2. Modify the HOSTNAME= value to match your FQDN hostname (for example):
  3. (optional) Change the hostname that is associated with the main IP address in /etc/hosts
  4. Reboot your server.

Set / Change the hostname via GUI

  1. Using the system-config-network command to start a text-based network configuration tool.
  2. Navigate using the Tab, arrow keys and Enter keys and select the DNS configuration option DNS Configuration
  3. Modify your preferred hostname and click OK. DNS Configuration
  4. Reboot your server