Friday 21 November 2008

How to change the name of a Solaris server

This script was written for Solaris 10, but it checks for the presence of all the files it wants to change and allows you to quit or continue if it doesn't find all of them. It was also written for a T2000, hence the interface name being e1000g0, but you can change that easily.


#Change oldname -> newname in the following files:
#
#/etc/hosts
#/etc/hostname.e1000g0 (or bge0)
#/etc/nodename
#/etc/dumpadm.conf
#/etc/inet/ipnodes
#/etc/inet/hosts
#/etc/mnttab
#/etc/sysidcfg

#Accomplish this with...

OLDNAME=old_name_of_server
NEWNAME=new_name_of_server
INTERFACE=e1000g0 (or bge0 and so on)

for FILE in /etc/hosts /etc/hostname.$INTERFACE /etc/nodename /etc/dumpadm.conf /etc/inet/ipnodes /etc/inet/hosts /etc/mnttab /etc/sysidcfg; do

count=0
if [[ ! -f $FILE ]]; then
echo $FILE not found
$count=$(( $count + 1 ))
fi

if [[ $count -gt 0 ]];then
GO="false"
while [[ $GO == "false" ]];do
print -n 'Continue anyway? y/n'
read ANSWER
if [[ "$ANSWER" == "y" ]] || [[ "$ANSWER" == "Y" ]]; then
echo "Okay."
GO="true"
elsif [[ "$ANSWER" == "n" ]] || [[ "$ANSWER" == "Y" ]]; then
echo "Quitting."
exit 0
else
echo "Sorry?"
fi
done
fi


sed s/$OLDNAME/$NEWNAME/g /etc/hosts > /etc/hosts_new
sed s/$OLDNAME/$NEWNAME/g /etc/hostname.$INTERFACE > /etc/hostname.$INTERFACE_new
sed s/$OLDNAME/$NEWNAME/g /etc/nodename > /etc/nodename_new
sed s/$OLDNAME/$NEWNAME/g /etc/dumpadm.conf > /etc/dumpadm.conf_new
sed s/$OLDNAME/$NEWNAME/g /etc/inet/ipnodes > /etc/inet/ipnodes_new
sed s/$OLDNAME/$NEWNAME/g /etc/inet/hosts > /etc/inet/hosts_new
sed s/$OLDNAME/$NEWNAME/g /etc/mnttab > /etc/mnttab_new
sed s/$OLDNAME/$NEWNAME/g /etc/sysidcfg > /etc/sysidcfg_new


#Make sure you back up the current settings...

cp hosts hosts_orig
cp hostname.$INTERFACE hostname.$INTERFACE_orig
cp nodename nodename_orig
cp dumpadm.conf dumpadm.conf_orig
cp inet/ipnodes inet/ipnodes_orig
cp inet/hosts inet/hosts_orig
cp mnttab mnttab_orig
cp sysidcfg sysidcfg_orig



#Feeling brave?

mv hosts_new hosts
mv hostname.$INTERFACE_new hostname.$INTERFACE
mv nodename_new nodename
mv dumpadm.conf_new dumpadm.conf
mv inet/ipnodes_new /inet/ipnodes
mv inet/hosts_new inet/hosts
mv mnttab_new mnttab
mv sysidcfg_new sysidcfg


#Now set the new name:

uname -S $NEWNAME


#Finally, restart:

shutdown -i 6 -g 0 -y

1 comment:

OutlanderLou said...

Nice! Clear, concise and *very* useful - even a newbie like myself can follow this. Thanks for posting it!