There are basically 2 ways to change the hostname in Solaris 10 and below. The post describes both these methods and also how to change hostname or IP address in Non-Global zones.
1. Using the sys-unconfig Command
sys-unconfig command restores the system’s configuration to an “as-manufactured” state, ready to be reconfigured again. This includes IP address, hostname, Name resolution choice, Time zone etc.
# sys-unconfig
The system needs to reboot after you run this command. It takes you through all the configuration steps when you first install the OS, like hostname, IP address, DNS settings, time zone etc..
2. Changing hostname without running sys-unconfig command
You can also change the hostname or IP address without the using the sys-unconfig command. this too requires a reboot.
For Solaris 10
Edit the below files and replace the old hostname and/or IP address wherever applicable.
/etc/inet/hosts /etc/nodename /etc/hostname.[interface]
In the last file, the interface is the primary interface that is being used in the system (for example e1000g0). This file may contain just the IP address. In that case you may leave the file unchanged, unless you want to change the IP address of the system too.
For Solaris 9 and below
For Solaris 9 and below, we need to also edit below files :
/etc/net/ticlts/hosts /etc/net/ticots/hosts /etc/net/ticotsord/hosts
Reboot the system
Reboot the system gracefully for the changes to take effect :
# shutdown -i6 -g0 -y
3. Changing hostname/zone-name or IP address in Non-global zone
1. Login into the zone and edit the below files :
/etc/inet/ipnodes /etc/inet/hosts
2. From the Global zone change the zone’s configuration :
root@global # zonecfg -z my-zone root@global # zonecfg:my-zone> set zonename=new_name root@global # zonecfg:newzone> commit root@global # zonecfg:newzone> set address=x.x.x.x (where x.x.x.x is the new address) root@global # zonecfg:newzone> end root@global # zonecfg:newzone> verify root@global # zonecfg:newzone> commit root@global # zonecfg:newzone> exit
3. Reboot the zone
root@global # zoneadm -z my-zone reboot
Other files to be edited
Now the hostname entry is added to many other files mentioned below. Make sure you edit these files to change them to have the new hostname.
--> /etc/hosts --> /etc/dfs/dfstab --> /etc/vfstab on the NFS clients --> Cronjobs where old hostname entries were used --> Scripts having the old hostname entry