LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > Solaris / OpenSolaris
User Name
Password
Solaris / OpenSolaris This forum is for the discussion of Solaris and OpenSolaris.
General Sun, SunOS and Sparc related questions also go here.

Notices

Reply
 
Search this Thread
Old 05-18-2006, 02:04 AM   #1
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 522

Rep: Reputation: 31
script to change IP and hostname under Solaris 10


Hi!

I have to migrate from solaris 9 to solaris 10. The solaris 10 is ready and I would like to test it. Therefore I would like to write a script in order to change easily the IP address and the hostname. Quite a lot of files seem to be involved. Should I reither use "sys-unconfig" or edit directly /etc/hostname.*, /etc/hosts, /etc/inet/ipnodes and /etc/nodename (any other files?). Does anyone have maybe such a script?

Under http://sysunconfig.net/unixtips/sola...ame_script.txt
I found a script to change the hostname:

Quote:
#!/usr/bin/bash

# Sandra Henry-Stocker - v. 1.0
# David Cashion - v. 1.1 - Corrected errors and added ipnodes

# ---- prompt for new hostname, current hostname is default ----
oldName=`uname -n`
newName=`ckstr -p "Enter new Hostname [$oldName]" -d $oldName`

# ---- confirm change ----
ok=`ckyorn -p "Change hostname to $newName?"`

case $ok in
[Yy]*)
echo OK
;;
[Nn]*)
echo exiting without changes
exit 1
;;
esac

# ---- make changes to /etc files ----
perl -i -p -e "s/$oldName/$newName/" /etc/nodename
perl -i -p -e "s/$oldName/$newName/" /etc/hostname.*
perl -i -p -e "s/$oldName/$newName/g" /etc/inet/hosts
# If it is a softlink, this will change it into a real file, we don't want that
[ ! -h /etc/hosts ] && perl -i -p -e "s/$oldName/$newName/g" /etc/hosts
perl -i -p -e "s/$oldName/$newName/g" /etc/inet/ipnodes

# ---- make changes to /etc/net files ----
for hostsFile in `find /etc/net -name hosts -print`
do
perl -i -p -e "s/$oldName/$newName/g" $hostsFile
done

# ---- move or create /var/crash directory ----
if [ -d /var/crash/$oldName ]; then
mv /var/crash/$oldName /var/crash/$newName
else
mkdir /var/crash/$newName
chmod 700 /var/crash/$newName
fi
dumpadm -s /var/crash/$newName

# ---- finally, change hostname ----
uname -S $newName

# ---- confirm changes ----
uname -a
But I do not understand exactly how it works and do not know how to expand it so that it also changes the IP address (I haven't tested it yet though, and I actually do not know if it works).

Thanks for your help.

Last edited by xpucto; 05-18-2006 at 02:05 AM.
 
Old 05-20-2006, 07:55 PM   #2
apt-get-dude
Member
 
Registered: Mar 2006
Posts: 98

Rep: Reputation: 15
I would just go with sys-unconfig. It is safer in my opinion.
 
Old 05-24-2006, 09:32 AM   #3
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 522

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by apt-get-dude
I would just go with sys-unconfig. It is safer in my opinion.
But as far as I understand, sys-unconfig removes a lot of infos like the nameservers in /etc/resolv.conf or Regenerates keys for sshd! I do not want this! I just would like to test another ip and another hostname and have them back quickly if there is a problem.

could
Quote:
ifconfig bge0 plumb
be a possibility to change the IP?
Is there a command to change only the hostname? Is it enough to change it in /etc/hostname ? Or does it have to be changed in many other files?

Thanks.
 
Old 05-24-2006, 11:48 PM   #4
mdhmi
Member
 
Registered: Dec 2005
Location: Detroit, Michigan
Distribution: Ubuntu
Posts: 86

Rep: Reputation: 15
I'm not a fan of sys-unconfig at all. Just change the /etc files and call it good.

Mark
 
Old 05-29-2006, 12:39 AM   #5
AbrahamJose
Member
 
Registered: Feb 2006
Location: India
Posts: 165

Rep: Reputation: 30
Post related files

/etc/hosts
/etc/nodename
/etc/hostname.*
Plus files listed by
find /etc -name hosts -print
 
Old 06-06-2006, 09:30 AM   #6
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 522

Original Poster
Rep: Reputation: 31
Ok. I wrote a script. It seems to work. I tested it. Its purpose is to change quickly between 2 IPs and hostnames. I took all the related files listed by AbrahamJose and also added /etc/inet/ipnodes.

Quote:
#!/bin/bash

OPTIONS="Backup IP-myhost1 IP-myhost2 Quit"
select opt in $OPTIONS; do
if [ "$opt" = "Quit" ]; then
echo The new IP and Hostname are:
cat /etc/hosts
cat /etc/nodename
cat /etc/hostname.bge0
cat /etc/inet/hosts
cat /etc/inet/ipnodes
echo done
echo You have to restart your computer!
exit

elif [ "$opt" = "Backup" ]; then
#Files'Backup
cp /etc/hosts /etc/hosts-back2
cp /etc/nodename /etc/nodename-back2
cp /etc/hostname.bge0 /etc/hostname.bge0-back2
cp /etc/inet/hosts /etc/inet/hosts-back2
cp /etc/inet/ipnodes /etc/inet/ipnodes-back2
echo Config Files have been backed-up

elif [ "$opt" = "IP-myhost1" ]; then
echo myhost1 has been chosen
cp /etc/hosts-myhost1 /etc/hosts
cp /etc/nodename-myhost1 /etc/nodename
cp /etc/hostname.bge0-myhost1 /etc/hostname.bge0
cp /etc/inet/hosts-myhost1 /etc/inet/hosts
cp /etc/apache2/httpd.conf-myhost1 /etc/apache2/httpd.conf
cp /etc/inet/ipnodes-myhost1 /etc/inet/ipnodes

echo The new IP and Hostname are:
cat /etc/hosts
cat /etc/nodename
cat /etc/hostname.bge0
cat /etc/inet/hosts
cat /etc/inet/ipnodes

elif [ "$opt" = "IP-myhost2" ]; then
echo myhost2 has been chosen
cp /etc/hosts-myhost2 /etc/hosts
cp /etc/nodename-myhost2 /etc/nodename
cp /etc/hostname.bge0-myhost2 /etc/hostname.bge0
cp /etc/inet/hosts-myhost2 /etc/inet/hosts
cp /etc/apache2/httpd.conf-myhost2 /etc/apache2/httpd.conf
cp /etc/inet/ipnodes-myhost2 /etc/inet/ipnodes

echo The new IP and Hostname are:
cat /etc/hosts
cat /etc/nodename
cat /etc/hostname.bge0
cat /etc/inet/hosts
cat /etc/inet/ipnodes


else
clear
echo bad option
fi
done

Last edited by xpucto; 06-06-2006 at 09:31 AM.
 
Old 06-07-2006, 03:12 AM   #7
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,909

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Just a remark.
There is no need to reboot for the changes to take effect. Just add to your script something like:
Code:
ifconfig bge0 down
ifconfig bge0 IP-myhost1 netmask xx.xx.xx.xx up
 
Old 06-07-2006, 05:04 AM   #8
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 522

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by bathory
Just a remark.
There is no need to reboot for the changes to take effect. Just add to your script something like:
Code:
ifconfig bge0 down
ifconfig bge0 IP-myhost1 netmask xx.xx.xx.xx up

I tried what you advice but it doesn't work. The server hangs and I have to set up everything back with the console since I loose every ssh connection and I cannot reconnect myself wether with the old nor with the new IP.

I also tried
Quote:
/sbin/ifconfig bge0 down
/sbin/ifconfig bge0 up
But it doesn't occure anything. I do not even lose the ssh-connection (shouldn't it be the case since the bge0 is being shut down?)
 
Old 06-07-2006, 07:41 AM   #9
bathory
Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 10,909

Rep: Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326Reputation: 1326
Oops, I thought that you're running the script locally and not through ssh.
Quote:
But it doesn't occure anything. I do not even lose the ssh-connection (shouldn't it be the case since the bge0 is being shut down?)
It should, but I guess this happens because, before the connection times out you bring back the interface up (keeping the old IP). To disable the interface you should run:
Code:
ifconfig bge0 unplumb
You can also try (locally of course) to run just:
Code:
ifconfig bge0 IP-myhost1 netmask xx.xx.xx.xx
This works for my sparc box and changes the IP instantly.
 
Old 06-08-2006, 05:37 AM   #10
xpucto
Member
 
Registered: Sep 2005
Location: Vienna, Austria
Distribution: Mint 13
Posts: 522

Original Poster
Rep: Reputation: 31
Quote:
Originally Posted by bathory
Oops, I thought that you're running the script locally and not through ssh.

It should, but I guess this happens because, before the connection times out you bring back the interface up (keeping the old IP). To disable the interface you should run:
Code:
ifconfig bge0 unplumb
You can also try (locally of course) to run just:
Code:
ifconfig bge0 IP-myhost1 netmask xx.xx.xx.xx
This works for my sparc box and changes the IP instantly.
Thanks. I'm running through ssh though. Locally is a bit complicated and not very comfortable. So I guess I'll keep the restart option.

Last edited by xpucto; 06-08-2006 at 05:51 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you change your Hostname? JGplt3095 Linux - Newbie 2 09-28-2005 02:02 PM
sendmail on solaris with no hostname & ipfw (or other firewall) tutorials Maidros Solaris / OpenSolaris 1 07-10-2005 01:34 PM
change hostname mikpos Linux - Networking 1 08-12-2004 12:19 PM
change hostname dincer80 Linux - Networking 3 07-31-2003 01:30 AM
change hostname kafnir Linux - Networking 1 10-21-2002 11:10 AM


All times are GMT -5. The time now is 05:33 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration