Welcome 微信登录

首页 / 操作系统 / Linux / CentOS 6 KVM添加网卡桥接口脚本

脚本任务1,判断网卡配置文件名称为eth*或者是em* ,如dell服务器网卡CentOS5为eth*,而CentOS6为em*。2,存在几个网卡就复制几个原网卡配置文件做为桥配置文件,n的设置的数量是3,如果超过4网卡则设置更高值,原配置文件是DHCP的改为static,用.*匹配行是存在CentOS5和6参数有引号的问题。4, 生成虚拟机桥借口br*并一一对应,如br0对应eth0,br1对应eth1等等,并重启网络。 #! /bin/sh
mypath="/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!"
fi
done
/etc/init.d/network restart更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14在Linux下开启背光Led键盘的背光关于Linux下的iptables 的浅析命令和了解相关资讯      KVM  CentOS 6 KVM 
  • 怎样在 Ubuntu 和 Debian 中通过命  (02月29日)
  • RHCSA 系列(十五): 虚拟化基础  (10/07/2015 15:25:43)
  • 在Ubuntu上安装KVM并搭建虚拟环境  (10/04/2015 06:28:17)
  • KVM嵌套虚拟化配置  (11/20/2015 20:16:53)
  • Ubuntu下使用KVM+Qemu 搭建虚拟机  (10/04/2015 06:48:51)
  • 如何在Linux发行版上安装和配置KVM  (10/04/2015 06:21:48)
本文评论 查看全部评论 (0)
表情: 姓名: 字数