本文共 1365 字,大约阅读时间需要 4 分钟。
脚本任务
1,判断网卡配置文件名称为eth*或者是em* ,如dell服务器网卡CentOS5为eth*,而CentOS6为em*。
2,存在几个网卡就复制几个原网卡配置文件做为桥配置文件,n的设置的数量是4,如果超过4网卡则设置更高值,原配置文件是DHCP的改为static,用.*匹配行是存在CentOS5和6参数有引号的问题。
3, 生成虚拟机桥借口br*并一一对应,如br0对应eth0,br1对应eth1等等,并重启网络。
#! /bin/shmypath="/etc/sysconfig/network-scripts"for((n=0;n<=4;n++)) do if [ -f "$mypath/ifcfg-eth$n" ] then sed -i "s/^ONBOOT.*/ONBOOT=yes/" $mypath/ifcfg-eth$n sed -i "s/^BOOTPROTO.*/BOOTPROTO=static/" $mypath/ifcfg-eth$n cp -a $mypath/ifcfg-eth$n $mypath/ifcfg-br$n sed -i "/^HWADDR.*/d" $mypath/ifcfg-br$n sed -i "s/^DEVICE.*/DEVICE=br"$n"/" $mypath/ifcfg-br$n sed -i "s/^TYPE.*/TYPE=Bridge/" $mypath/ifcfg-br$n echo "BRIDGE=br$n">>$mypath/ifcfg-eth$n echo "The device br$n<---->eth$n is add success !" else echo "The device eth$n not exist!" fi if [ -f "$mypath/ifcfg-em$n" ] then sed -i "s/^ONBOOT.*/ONBOOT=yes/" $mypath/ifcfg-em$n sed -i "s/^BOOTPROTO.*/BOOTPROTO=static/" $mypath/ifcfg-em$n cp -a $mypath/ifcfg-em$n $mypath/ifcfg-br$n sed -i "/^HWADDR.*/d" $mypath/ifcfg-br$n sed -i "s/^DEVICE.*/DEVICE=br"$n"/" $mypath/ifcfg-br$n sed -i "s/^TYPE.*/TYPE=Bridge/" $mypath/ifcfg-br$n echo "BRIDGE=br$n">>$mypath/ifcfg-em$n echo "The device br$n<---->em$n is add success !" else echo "The device em$n not exist!"fidone/etc/init.d/network restart
转载于:https://blog.51cto.com/songxj/1070725