<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">As at least one other has said be sure to save copies of the original ifcfg-&lt;ifc&gt; files.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">However, be sure NOT to save that copy in same directory as the original (e.g. /etc/sysconfig/network-scripts on RHEL/CentOS).&nbsp;&nbsp; On networking start it actually
 tries to load all ifcfg files even if they are describing the same interface and the last one found wins so you might end up with unexpected settings.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D">You want to make sure you have&nbsp; console access available just in case something goes wrong and networking doesn’t start.&nbsp;&nbsp; In general though restarting networking
 is fairly painless.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;color:#1F497D"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;">From:</span></b><span style="font-size:10.0pt;font-family:&quot;Tahoma&quot;,&quot;sans-serif&quot;"> ale-bounces@ale.org [mailto:ale-bounces@ale.org]
<b>On Behalf Of </b>Jim Kinney<br>
<b>Sent:</b> Sunday, March 19, 2017 9:50 AM<br>
<b>To:</b> Atlanta Linux Enthusiasts - Yes! We run Linux!<br>
<b>Subject:</b> Re: [ale] Update ifcfg-eth0 file from command line? (need to re-ip 50 servers)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">sed -i -e 'edit #1' -e 'edit #2' ... -e 'edit #n’&nbsp;<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
<div>
<p class="MsoNormal">The edits happen in sequence per line.<o:p></o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal">On Mar 19, 2017 12:46 AM, &quot;Raj Wurttemberg&quot; &lt;<a href="mailto:rajaw@c64.us">rajaw@c64.us</a>&gt; wrote:<o:p></o:p></p>
<p class="MsoNormal">Hey Phil,<br>
<br>
Can't say that I even knew that sed could do multiple replacements in one<br>
line. :)&nbsp; (I've only been scripting with bash for about two years... I'm a<br>
noob) I just Googled it and came up with this...<br>
<br>
Is this kind of what you are talking about? (I've never used mktemp either)<br>
<br>
TMPIPCFG=$(mktemp /etc/sysconfig/network-scripts/tmpipcfg.XXXX)<br>
sed -i 's/IPADDR=.*/IPADDR=<a href="http://1.2.3.4/" target="_blank">1.2.3.4/</a>; s/BROADCAST=.*/BROADCAST=<a href="http://1.2.3.0/" target="_blank">1.2.3.0/</a>;<br>
s/GATEWAY=.*/GATEWAY=<a href="http://1.2.3.1/" target="_blank">1.2.3.1/</a>' $TMPIPCFG<br>
mv $TMPIPCFG /etc/sysconfig/network-scripts/ifcfg-eth0<br>
<br>
Learned something new tonight...<br>
<br>
Thanks!<br>
/Raj<br>
<br>
-----Original Message-----<br>
From: <a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a> [mailto:<a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a>] On Behalf Of Phil<br>
Turmel<br>
Sent: Saturday, March 18, 2017 9:56 PM<br>
To: <a href="mailto:ale@ale.org">ale@ale.org</a><br>
Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to re-ip<br>
50 servers)<br>
<br>
Aaaaahhhhhhgggg!<br>
<br>
Raj, Leam, y'all making me cringe with those procedures.&nbsp; For pity's sake,<br>
use mktemp to safely make an empty temp file in the *same* folder, stream<br>
from the original to the temp file with *one* instance of sed, then 'mv' the<br>
temp file back over the original.&nbsp; At no point will you have a partially<br>
configured network -- filesystems are required to guarantee that renaming<br>
over file atomically replaces it.&nbsp; And at no point will you have an unsecure<br>
temp file exposed.<br>
<br>
Phil<br>
<br>
On 03/18/2017 09:03 PM, Raj Wurttemberg wrote:<br>
&gt; Yeah, I was actually going to do a sed to just replace the old values and<br>
do most everything in one step:<br>
&gt;<br>
&gt; sed -i 's/IPADDR=.*/IPADDR=<a href="http://1.2.3.4/" target="_blank">1.2.3.4/</a>'<br>
&gt; /etc/sysconfig/network-scripts/ifcfg-eth0 2&gt; /dev/null sed -i<br>
&gt; 's/BROADCAST=.*/BROADCAST=<a href="http://1.2.3.0/" target="_blank">1.2.3.0/</a>'<br>
&gt; /etc/sysconfig/network-scripts/ifcfg-eth0 2&gt; /dev/null sed -i<br>
&gt; 's/GATEWAY=.*/GATEWAY=<a href="http://1.2.3.1/" target="_blank">1.2.3.1/</a>'<br>
&gt; /etc/sysconfig/network-scripts/ifcfg-eth0 2&gt; /dev/null<br>
&gt;<br>
&gt; haha... yes, I noticed a long time ago that the RHEL tries to use any file<br>
in the /etc/sysconfig/network-scripts directory! Doh!<br>
&gt;<br>
&gt; Thanks,<br>
&gt; /Raj<br>
&gt;<br>
&gt;<br>
&gt; -----Original Message-----<br>
&gt; From: <a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a> [mailto:<a href="mailto:ale-bounces@ale.org">ale-bounces@ale.org</a>] On Behalf Of<br>
&gt; Leam Hall<br>
&gt; Sent: Saturday, March 18, 2017 8:32 PM<br>
&gt; To: Atlanta Linux Enthusiasts &lt;<a href="mailto:ale@ale.org">ale@ale.org</a>&gt;<br>
&gt; Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to<br>
&gt; re-ip 50 servers)<br>
&gt;<br>
&gt; Untested, and I tend to do things in multiple steps.<br>
&gt;<br>
&gt; cp /etc/sysconfig/network-scripts/ifcfg-eth0 /tmp<br>
&gt;<br>
&gt; cat /tmp/ifcfg-eth0 | egrep -iv &quot;ipaddr|broadcast|gateway&quot; &gt;<br>
&gt; /etc/sysconfig/network-scripts/ifcfg-eth0<br>
&gt;<br>
&gt; echo &quot;IPADDR=1.2.3.4&quot; &gt;&gt; /etc/sysconfig/network-scripts/ifcfg-eth0<br>
&gt; echo &quot;BROADCAST=1.2.3.0&quot; &gt;&gt; /etc/sysconfig/network-scripts/ifcfg-eth0<br>
&gt; echo &quot;GATEWAY=1.2.3.1&quot; &gt;&gt; /etc/sysconfig/network-scripts/ifcfg-eth0<br>
&gt;<br>
&gt; service network restart<br>
<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><br>
<br>
_______________________________________________<br>
Ale mailing list<br>
<a href="mailto:Ale@ale.org">Ale@ale.org</a><br>
<a href="http://mail.ale.org/mailman/listinfo/ale" target="_blank">http://mail.ale.org/mailman/listinfo/ale</a><br>
See JOBS, ANNOUNCE and SCHOOLS lists at<br>
<a href="http://mail.ale.org/mailman/listinfo" target="_blank">http://mail.ale.org/mailman/listinfo</a><o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>