CentOS 6 KVM添加網卡橋介面指令碼

來源:互聯網
上載者:User

指令碼任務

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.