How to create many ifcfg-ethN files in one shot

I had a quick task to create 254 ifcfg-eth1:N configuration files for a Linux installation and certainly spending the whole day doing that manually wasn’t part of my plan. Here is a quick and dirty one-liner I used for that:

# for f in `seq 2 254`; do cat ifcfg-eth1 | \ 
sed -e 's/DEVICE=.*$/DEVICE=eth1\:'$f'/' \
-e 's/IPADDR=.*$/'$f'/' \
-e 's/ONBOOT=.*$/ONPARENT=yes/' > ifcfg-eth1\:$f; done

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.