Sponsored Content
Special Forums IP Networking Script for Changing an IP address remotely Post 302243550 by nua7 on Monday 6th of October 2008 03:12:27 AM
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"

 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
USERNETCTL(8)						      System Manager's Manual						     USERNETCTL(8)

NAME
usernetctl - allow a user to manipulate a network interface if permitted SYNOPSIS
usernetctl interface-name up|down|report DESCRIPTION
usernetctl checks to see if users are allowed to manipulate the network interface specified by interface-name, and then tries to bring the network interface up or down, if up or down was specified on the command line, or returns true or false status (respectively) if the report option was specified. usernetctl is not really meant to be called directly by users, though it currently works fine that way. It is used as a wrapper by the ifup and ifdown scripts, so that users can do exactly the same thing as root: ifup interface-name ifdown interface-name and ifup and ifdown will call usernetctl automatically to allow the interface status change. OPTIONS
interface-name The name of the network interface to check; for example, "ppp0". For backwards compatibility, "ifcfg-ppp0" and "/etc/sysconfig/net- work-scripts/ifcfg-ppp0" are also supported. up|down Attempt to bring the interface up or down. report Report on whether users can bring the interface up or down. NOTES
Alternate device configurations may inherit the default configuration's permissions. RHS
Red Hat, Inc. USERNETCTL(8)
All times are GMT -4. The time now is 03:40 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy