Script for Changing an IP address remotely


 
Thread Tools Search this Thread
Special Forums IP Networking Script for Changing an IP address remotely
# 1  
Old 10-06-2008
Data Script for Changing an IP address remotely

Hi Fellows,

I am a beginner in shell scripting struggling with a script.
I have to write a script to change the IP address of computer remotely running on solaris or Linux ,which is to be added to a cluster.I am working on unix.

Presently the administrator runs a sanity check script on the computer remotely of course.If IP address i not as predefined then he has to change it manually.

I hope I have expained my poblem correctly.

Please Help or tell if I need to explain more.

Pranav
# 2  
Old 10-06-2008
This is what we use to assign a ip to a new machine. This would give you an idea, please make changes according to your requirements..


Code:
#!/bin/ksh
###############################################################################
#                                                                             #
# NAME        : cnfg_cm.sh                                                    #
# DESCRIPTION : This script will make changes in the following files:         #
#               a)/etc/sysconfig/network-scripts/ifcfg-eth0                   #
#               b)/etc/hosts                                                  #
#               c)/etc/sysconfig/network                                      #
#               d)/etc/security/access.conf                                   #
#                                                                             #        
#                                                                             #
#  Ver  Date      Description                            Analyst              #
#  ---  --------  -------------------------------        ---------------      #
#  A00  02-06-08  Original implementation                nua7                 #
###############################################################################
#Usage of the script is as follows:
#checking the variables passed
if [ $# -lt 2 ] ; then
      echo need 2 files  
      exit 0
fi
######
# Ensuring that only root can run this script
######
logonID=`whoami`
if test "$logonID" != "root"
then
  echo "\nYou should logon as MGR for running this script"
  exit
fi
#setting up variables
ips=$1
domain_name=".xyz.com"
mc_name=$2
export ips
#Modifying the ifcfg-eth0 file
awk -v ip=$ips '/ONBOOT=no/{
print
print "DEVICE=eth0"
print "BOOTPROTO=static"
print "IPADDR=" ip
print "NETMASK=255.255.255.0"
print "GATEWAY=123.123.123.1"
next
}1' /etc/sysconfig/network-scripts/ifcfg-eth0> /etc/sysconfig/network-scripts/temp1

sed -e's/no/yes/' /etc/sysconfig/network-scripts/temp1 > /etc/sysconfig/network-scripts/temp2

rm /etc/sysconfig/network-scripts/ifcfg-eth0
mv /etc/sysconfig/network-scripts/temp2 ifcfg-eth0
chmod 644 /etc/sysconfig/network-scripts/ifcfg-eth0
rm /etc/sysconfig/network-scripts/temp1
rm /etc/sysconfig/network-scripts/temp2

#Modifying /etc/hosts
echo $ips $mc_name$domain_name $mc_name > /etc/host2
sed -e's/127.0.0.1/#127.0.0.1/' /etc/hosts > /etc/host1
rm /etc/hosts
mv /etc/host1 /etc/hosts
hostname $mc_name
rm /etc/host1
rm /etc/host2

#Modifying access.conf

sed -e's/-:root/#-:root/' /etc/security/access.conf > /etc/security/access1.conf
rm /etc/security/access.conf
mv /etc/security/access1.conf /etc/security/access.conf
rm /etc/security/access1.conf
echo "Don't forget to reboot the system"

# 3  
Old 10-06-2008
thanks a lot
# 4  
Old 10-06-2008
another query

Thanks a lot for the script.It worked after making some minor changes.

I have one more query.

I have a script which finds the subnet of the computer from the first three octets of the ip address.
And then obtains rest of the networking information like dns,gateway,route list,etc from ldapsearch.

At the moment this script only obtains the values and displays the values on screen.

How do I get the script to refelect the changes on the machine itself automatically

Waiting for a response.

Pranav
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

Changing IP address

My work has a Unix based system that currently has the IP address 192.9.2.25 We recently changed internet providers from DSL to Cable. By doing so, we had to get a new router (Belkin) since the DSL provider had a wireless router/modem in one. With the DSL setup, I was able to change the router's... (2 Replies)
Discussion started by: Len351
2 Replies

2. Cybersecurity

Port Address Changing....

Is there a software solution to stop intruders from changing my port addresses? Causes IPmap to crash. Platform is OS/X Leopard. (1 Reply)
Discussion started by: aleatory
1 Replies

3. AIX

changing ip address

Hi, I am using aix 5300-07, I am facing strange issue in aix. I have changed the ip address and gateway of aix server , it is showing the right ip address but it is taking old gateway ip address. I have used netstat -r command and found it is showing 2 Default gateway. I want to... (2 Replies)
Discussion started by: manoj.solaris
2 Replies

4. Windows & DOS: Issues & Discussions

Changing IP address

Hi ,,, i just come across this forum and i make it a must to be pay a visit here everyday and through it am learning a lots of things which am sure i will be able to share later... So i have a prob with my pc when i try to change my Ip address in the dos command using ipconfig command i got a... (1 Reply)
Discussion started by: Lutchumaya
1 Replies

5. Shell Programming and Scripting

changing passwords remotely on sun boxes

now, for reasons i really cant begin to delve into, i have to find a way to be able to rmeotely create user accounts and also assign them passwords. unfortunately, it appears Sun boxes frowns upon this. sun boxes will let u create a user account remotely but will never let u assign the useraccount... (0 Replies)
Discussion started by: Terrible
0 Replies

6. IP Networking

Changing the ip address

Help me save my Unix box. I've had this Unix box (Enterprise 450) for about 7 years now. It was being used as a file server for a Macintosh Prepress department. All of our networking was done through Helios Etharshare. I am still currently up and online (however the location has changed). Our ip... (1 Reply)
Discussion started by: ubed
1 Replies

7. AIX

Changing the IP Address

I need to change the IP address on one of your Unix machines - P630, AIX5.2. I plan on using SMIT to perform this function. These are the steps that I have put together so far: 1. Select Communications Applications & Services - Select TCP/IP - Select Minimun Configuration & Startup... (2 Replies)
Discussion started by: jyoung
2 Replies

8. UNIX for Dummies Questions & Answers

Changing IP address

Hi, I am going to shift my Unix workstation to another lab. So I need to change the IP address. Please tell me how to change the Network IP address, what is the commands, what to take care? Thank you very much and have a very nice day. (4 Replies)
Discussion started by: champion
4 Replies

9. UNIX for Advanced & Expert Users

Changing Machine IP address

Hopefully someone can help with this. I need the command to change the IP address on a machine (7 Replies)
Discussion started by: kkinnon
7 Replies

10. UNIX for Dummies Questions & Answers

Changing IP address with set_params

I want to change the IP address of my computer (743i card using HP-UX 10.2) using "set_params ip_address". The problem is the following: 1. I'm using a touch panel to enter in the IP address. 2. The set_params routine asks two questions; do I want to use the IP address entered and do I want... (3 Replies)
Discussion started by: maddog0606
3 Replies
Login or Register to Ask a Question