Add: This is valid for the first time to add a network card, if you need to repeat the addition and deletion of automatic configuration, you need to change the script, according to the IP a command information to modify.
Copy Code code as follows:
#!/bin/bash
#update: 2013-02-25
#author: Ihuotui
#version 0.1
cdate=$ (date ' +%y%m%d ')
num=$ (ifconfig-a | grep eth | wc-l)
echo "ethx=" $num >> ethx
For ((n=1;n<${num};n++))
Todo
If [-e/etc/sysconfig/network-scripts/ifcfg-eth${n}]; Then
Sed-i '/hwaddr/d '/etc/sysconfig/network-scripts/ifcfg-eth${n}
ifconfig-a | grep "Eth${n}" | awk ' {print ' hwaddr=\ ' $ ' \ '} ' >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
Else
Touch/etc/sysconfig/network-scripts/ifcfg-eth${n}
ifconfig-a | grep "Eth${n}" | awk ' {print ' hwaddr=\ ' $ ' \ '} ' >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo nm_controlled= "\" yes\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo onboot= "\" yes\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo type= "\" Ethernet\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo bootproto= "\" Dhcp\ "" >>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo uuid= "\" 2460e474-fad8-4b46-baba-da6f45ae158 "${n}" \ ">>/etc/sysconfig/network-scripts/ifcfg-eth${n}
echo device= "\" ETH "${n}" \ ">>/etc/sysconfig/network-scripts/ifcfg-eth${n}
Continue
Fi
Done