Solved

script to change the ip addresses in the ifcfg files

Posted on 2011-09-29
3
414 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
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
wesly_chen earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
many thanks!!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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é.
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now