Changing your Red Hat Enterprise or CentOS Linux server's hostname does not require rebooting the system; only restarting services. And does not interrupt system operations.
For this example, we are promoting a RHEL development system named RD13 to production and therefore need to rename it RP13. The scope is limited to the operating system only; DNS and application specific changes are not discussed. It is strongly suggested ALL relevant DNS and application configuration changes be made first - before proceeding.
1) After making a backup /etc/hosts copy, replace the existing primary IP address canonical name and aliases with the new values. Note that the canonical name (FQDN) is first, the alias (short) is second. Note the updated line has 'rp', not 'rd'.
#diff hosts.orig hosts
< 192.168.1.10 rd13.example.com rd13
---
> 192.168.1.10 rp13.example.com rp13
Alternatively, comment out the line completely and use DNS. Larger enterprises with reliable, redundant DNS services can centralize system name management there and deprecate the /etc/hosts file. Note the updated file begins the line with a '#'.
#diff hosts.orig hosts
< 192.168.1.10 rd13.example.com rd13
---
> #192.168.1.10 rp13.example.com rp13
2) After making a backup /etc/sysconfig/network copy, replace the existing HOSTNAME value with "localhost.localdomain". Note the updated line has 'rp', not 'rd'.
#diff network.orig network
< HOSTNAME=rd13.example.com
---
> HOSTNAME=rp13.example.com
Again alternatively, use localhost. Thus deprecating the /etc/sysconfig/network file's HOSTNAME attribute.
#diff network.orig network
< HOSTNAME=rd13.example.com
---
> HOSTNAME=localhost.localdomain
3) The final change is to set the new system name using the hostname command.
# hostname rp13.example.com
4) With the changes completed, restart the nscd and network services to enable the new hostname on the system.
# /etc/init.d/nscd reload; /etc/init.d/network restart
5) Verify the changes with the hostname and dnsdomainname commands. Your results should return the system short hostname, full hostname and domain name. Watch for errors like the full hostname not containing the domain; or alternatively, the short hostname containing the domain.
# hostname -sv
gethostname()=`rp13'
rp13
# hostname -fv
gethostname()=`rp13'
Resolving `rp13' ...
Result: h_name=`rp13.example.com'
Result: h_aliases=`rp13'
Result: h_addr_list=`192.168.1.10'
rp13.example.com
# dnsdomainname -v
gethostname()=`rp13'
Resolving `rp13' ...
Result: h_name=`rp13.example.com'
Result: h_aliases=`rp13'Result: h_addr_list=`192.168.1.10'
example.com
# hostname -sv; hostname -fv; dnsdomainname -v
[...]
Note that if you have used the DNS alternative options in steps one and two, the hostname command setting is effective only until the next system reboot. If it does not match the DNS reverse look-up for the system's IP address, the DNS name will be assumed as the new hostname.
Comments