[ale] Update ifcfg-eth0 file from command line? (need to re-ip 50 servers)
Raj Wurttemberg
rajaw at c64.us
Sat Mar 18 21:23:03 EDT 2017
Haha! Yeah, me too! I'll be pushing this with VMware's PowerCLI 'Invoke-VMScript' cmdlet (You can do some really cool stuff with 'Invoke-VMScript'!!), but you definitely have a valid point. I will take your advice and make a backup to /tmp.
FYI... VMware's 'Invoke-VMScript' is kinda cool because you do *not* need IP connectivity or even ssh to remotely reconfigure a server.
Example snippet below lets me update the fstab file on a guest Linux server...
$script_fst_sapsw = "echo -e ""x.x.x.x:/nfs /sapsw nfs rw,bg,vers=3,tcp,hard,noatime,nodirartime 0 0"" >> /etc/fstab"
$script_fst_import = "echo -e ""x.x.x.x:/nfs /import nfs rw,bg,vers=3,tcp,hard,noatime,nodirartime 0 0"" >> /etc/fstab"
Invoke-VMScript -VM $vmn -ScriptText $script_fst_saptrans -GuestOSUser root -GuestOSPassword $guestpw | out-null
Invoke-VMScript -VM $vmn -ScriptText $script_fst_import -GuestOSUser root -GuestOSPassword $guestpw | out-null
Thanks!
/Raj
-----Original Message-----
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of Leam Hall
Sent: Saturday, March 18, 2017 9:07 PM
To: Atlanta Linux Enthusiasts <ale at ale.org>
Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to re-ip 50 servers)
I type poorly, having a backup copy is nice. :)
On 03/18/17 21:03, Raj Wurttemberg wrote:
> Yeah, I was actually going to do a sed to just replace the old values and do most everything in one step:
>
> sed -i 's/IPADDR=.*/IPADDR=1.2.3.4/'
> /etc/sysconfig/network-scripts/ifcfg-eth0 2> /dev/null sed -i
> 's/BROADCAST=.*/BROADCAST=1.2.3.0/'
> /etc/sysconfig/network-scripts/ifcfg-eth0 2> /dev/null sed -i
> 's/GATEWAY=.*/GATEWAY=1.2.3.1/'
> /etc/sysconfig/network-scripts/ifcfg-eth0 2> /dev/null
>
> haha... yes, I noticed a long time ago that the RHEL tries to use any file in the /etc/sysconfig/network-scripts directory! Doh!
>
> Thanks,
> /Raj
>
>
> -----Original Message-----
> From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of
> Leam Hall
> Sent: Saturday, March 18, 2017 8:32 PM
> To: Atlanta Linux Enthusiasts <ale at ale.org>
> Subject: Re: [ale] Update ifcfg-eth0 file from command line? (need to
> re-ip 50 servers)
>
> Untested, and I tend to do things in multiple steps.
>
> cp /etc/sysconfig/network-scripts/ifcfg-eth0 /tmp
>
> cat /tmp/ifcfg-eth0 | egrep -iv "ipaddr|broadcast|gateway" >
> /etc/sysconfig/network-scripts/ifcfg-eth0
>
> echo "IPADDR=1.2.3.4" >> /etc/sysconfig/network-scripts/ifcfg-eth0
> echo "BROADCAST=1.2.3.0" >> /etc/sysconfig/network-scripts/ifcfg-eth0
> echo "GATEWAY=1.2.3.1" >> /etc/sysconfig/network-scripts/ifcfg-eth0
>
> service network restart
>
> Main thing is to not put the backup copy in the network-scripts directory, RHEL will try to bring up an interface like ifcfg-eth0.sav.
>
> Hope that helps.
>
> Leam
>
>
> On 03/18/17 20:21, Raj Wurttemberg wrote:
>> Is it possible to edit the ifcfg-eth0 file (RHEL6) from the command
>> line? On my Windows servers I can use the netsh command to make the
>> change (I wrote a VMware PowerCLI script to update Windows already).
>> If I have to use sed or whatever, that’s fine… I was just curious if
>> there were an easier way.
>>
>>
>>
>> One of our hosted customers wants us to re-IP all of their servers
>> and I definitely don’t want to log into each server to make the
>> change. :p
>>
>>
>>
>> (Side note… I do have Salt running in the environment also.) Ugh…
>> that reminds me…. Salt doesn’t like it when servers get re-IPd….
>>
>>
>>
>> Thanks,
>>
>> /Raj
>>
>>
>>
>>
>>
>> _______________________________________________
>> Ale mailing list
>> Ale at ale.org
>> http://mail.ale.org/mailman/listinfo/ale
>> See JOBS, ANNOUNCE and SCHOOLS lists at
>> http://mail.ale.org/mailman/listinfo
>>
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://mail.ale.org/mailman/listinfo/ale
> See JOBS, ANNOUNCE and SCHOOLS lists at
> http://mail.ale.org/mailman/listinfo
>
_______________________________________________
Ale mailing list
Ale at ale.org
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
More information about the Ale
mailing list