Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

script to change the ip addresses in the ifcfg files

Posted on 2011-09-29
3
Medium Priority
?
447 Views
Last Modified: 2012-05-12
Does anyone have a bash or ksh script to change the ip addresses in ifcfg-* files
0
Comment
Question by:lolaferrari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 2000 total points
ID: 36818481
chmod  +x change_ip.sh
./change_ip.sh  <New IP>
#!/bin/bash

NEW_IP=$1
IFCFG_FILE=/etc/sysconfig/network-scripts/ifcfg-eth0

# remove the old IP address
sed '/^IPADDR=/d'  $IFCFG_FILE  > /tmp/ifcfg-eth0_$$

# Add new IP address 
echo "IPADDR=$NEW_IP" >>  /tmp/ifcfg-eth0_$$ 

# Backup the old file
/bin/mv  $IFCFG_FILE  ${IFCFG_FILE}.old

/bin/cp -f  /tmp/ifcfg-eth0_$$  $IFCFG_FILE

/bin/rm -f /tmp/ifcfg-eth0_$$

Open in new window

0
 
LVL 38

Expert Comment

by:wesly_chen
ID: 36818526
Or make is shorter

perl -i.bak -pe 's/IPADDR=.*/IPADDR=<NEW IP>/g'   /etc/sysconfig/network-scripts/ifcfg-eth0
  where replace <NEW IP> to actual IP like 192.168.0.123
0
 

Author Closing Comment

by:lolaferrari
ID: 36818649
many thanks!!
0

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question