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 schlumpf.localdomain
# grep -i hostname /etc/sysconfig/network HOSTNAME=schlumpf.localdomain
Set / Change the hostname via comand-line
- Using a text editor, open the servers
/etc/sysconfig/network
file.% sudo vi /etc/sysconfig/network
- Modify the
HOSTNAME=
value to match your FQDN hostname (for example):HOSTNAME=pitufo.localdomain
- (optional) Change the hostname that is associated with the main IP address in
/etc/hosts
- Reboot your server.
Set / Change the hostname via GUI
- Using the
system-config-network
command to start a text-based network configuration tool. - Navigate using the Tab, arrow keys and Enter keys and select the
DNS configuration
option - Modify your preferred hostname and click OK.
- Reboot your server