Skip to main content

I made a GIF!

Changing RHEL/CentOS 5.x hostname without reboot


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

Popular posts from this blog

Cisco ASA ICMP packet-tracer

Occasionally devices fail to respond to a ping.  This can result from devices being off-line, having a local firewall enabled or the perimeter firewall configuration.  The Cisco ASA ICMP packet-tracer options differ from the TCP or UDP command options.  An example is below: packet-tracer input outside icmp A.B.C.D 8 0 E.F.G.H The ICMP type is "8" (echo request) with code"0" (none).  There are no options on destination IPv4 address E.F.G.H. Complete ICMP documentation at URL http://www.iana.org/assignments/icmp-parameters/ Complete Cisco ASA packet-tracer documentation at URL http://www.cisco.com/en/US/docs/security/asa/asa80/command/reference/p.html#wp1878788

Xfce4 lock screen not working

Xfce4 would not start a screensaver on my Linux system.  Researching it, it ran xflock4 from the command line ad received an error: Property "/general/LockCommand" does not exist on channel "xfce4-session". To fix this, additional configuration needed, but no hacks. First, verify xflock4 and xfconf-query are available. $ which xflock4 xfconf-query /bin/xflock4 /bin/xfconf-query Next  install a lock screen package that provides 'xlock', 'slock', 'i3lock' or similar.  $ sudo yum install -y xlockmore-gtk i3lock Last, add an executable (with options) as /general/LockCommand in the xfce4-session settings. $ xfconf-query -c xfce4-session --create -p /general/LockCommand --set "xlock -mode matrix" --type  string $ xfconf-query -c xfce4-session --create -p /general/LockCommand --set "i3lock -c 000000" --type string Test by running xflock4 from the command line or through the GUI.

X11 Forwarding issue solved

TL;DR Disabling IPv6 necessitates SSHd AddressFamily is "inet" for X11 Forwarding to work. Issue OpenSSH assumes both IPv6 and IPv4 protocols are enabled, and default SSHd AddressFamily value "any" is valid. Quickly skimming the OpenSSH source code, it was not obvious why SSHd does not fail gracefully, selecting only an available IP address family. Therefore, for X11 Forwarding to work correctly, in /etc/ssh/sshd_config we must choose: Defaults - IPv6 enabled and SSHd AddressFamily value " any " Custom - IPv6 disabled and SSHd AddressFamily value " inet " Background PuTTY was not creating a $HOME/.Xauthority file on ssh login and no X11 applications would run, despite setting $DISPLAY.  PuTTY was correctly configured with: X11 Forwarding enabled X display location empty Remote authentication protocol MIT-Magic-Cookie-1 X authority file for local display empty On the initial ssh login there should be a .Xauthority notic