Linux – llinux – replace subnet mask in ifcfg-eth0 with sed or awk

bashcentoslinuxscriptingsed

I have 30 linux servers that I need to change subnetmask. I want to use a simple script or a simple command to change the subnemt mask from 255.255.255.128 to 255.255.255.0 in ifcfg-eth0.

can someone please help?
Thanks,
Elad.

Best Answer

A simple sed command like this will do it:

$ sudo sed -i 's/NETMASK=255.255.255.0/NETMASK=255.255.255.128/' /etc/sysconfig/network-scripts/ifcfg-eth0

You can combine this sed command with SSH command to execute this on each server using the a command like:

$ ssh user@server command