How to change the Solaris host name on fly

All the hosts which are in same network should have unique hostname.In this post,we will see that how to change the hostname of the Solaris machine.

To change the hostname on fly . (Applicable for Global & local zone)
(Not recommend while running applications)
bash-3.00# hostname node2
To make this change persistent you have to modify the below mentioned three files. 
Cause:Don’t rename the host in fly , it may affect the running applications on the system. 

Now you can see hostname got changed to node2
bash-3.00# uname -a
SunOS node2 5.10 Generic_142910-17 i86pc i386 i86pc

Global zone:
To check the current hostname
bash-3.00# uname -a
SunOS node1 5.10 Generic_142910-17 i86pc i386 i86pc

Configured IP address
bash-3.00# ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet netmask ff000000
e1000g0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet netmask ffffff00 broadcast
        ether 0:c:29:89:e8:8d

Current hosts file.
bash-3.00# cat /etc/hosts
# Internet host table
::1 localhost localhost node1 loghost

In order to chnage the hostname ,we have to modify three files

First you need to modifiy /etc/hosts file
“/etc/hosts” [Read only] 6 lines, 88 characters
# Internet host table
::1 localhost localhost node2 loghost

Second, you need to modifiy  /etc/hostname.XXXX
bash-3.00# vi /etc/hostname.e1000g0
“/etc/hostname.e1000g0” 1 line, 6 characters

Third, you need to modifiy /etc/nodename
bash-3.00# vi /etc/nodename
“/etc/nodename” 1 line, 6 characters

After modifying the above files,you need to reboot the server to take effect.
Non global zone:
How to rename a zone (hostname) and change IP Address

# Login into zone using zlogin command
Edit the files with the new values hostname and IP Address:
  1. /etc/inet/ipnodes
  2. /etc/inet/hosts
# Global ZONE
Change hostname and IP Address by “zonecfg” command.

# global# zonecfg -z arenazone
# zonecfg:arenazone> set zonename=newhost
# zonecfg:newhost> commit
# zonecfg:newhost> set
# zonecfg:newhost> end
# zonecfg:newhost> verify
# zonecfg:newhost> commit
# zonecfg:newhost> exit

# Reboot the zone
global# zoneadm -z arenazone reboot

Thank you for reading this article.

Please leave a comment if you have any doubt ,i will get back to you as soon as possible.