码迷,mamicode.com
首页 > 其他好文 > 详细

对interface文件操作

时间:2014-05-14 17:54:12      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:interface   running   gateway   address   null   

old:

auto lo

iface lo inet loopback


auto eth1

iface eth1 inet static

       address 10.0.13.13

       netmask 255.255.255.0


auto br0

       iface br0 inet static

       address 1.1.1.1

       netmask 255.255.255.0

       gateway 1.1.1.1

       bridge_ports eth0

       bridge_stp off

       bridge_fd 0

       bridge_maxwait 0

       dns-nameservers 202.106.0.20 202.106.196.115

       post-up for i in `virsh list | grep running| awk ‘{print $2}‘|tr "\n" " " `;do brctl show | grep $i >/dev/null; [ "$?" != "0" ] && brctl addif br0 $i;done



new:

auto lo

iface lo inet loopback



auto br1

       iface br1 inet static

       address 10.0.13.13

       netmask 255.255.255.0

       bridge_ports eth1

       bridge_stp off

       bridge_fd 0

       bridge_maxwait 0

       dns-nameservers 202.106.0.20 202.106.196.115


auto br0

       iface br0 inet static

       address 1.1.1.1

       netmask 255.255.255.0

       gateway 1.1.1.1

       bridge_ports eth0

       bridge_stp off

       bridge_fd 0

       bridge_maxwait 0

       dns-nameservers 202.106.0.20 202.106.196.115

#       post-up for i in `virsh list | grep running| awk ‘{print $2}‘|tr "\n" " " `;do brctl show | grep $i >/dev/null; [ "$?" != "0" ] && brctl addif br0 $i;done

       post-up for i in `virsh list | grep running| awk ‘{print $2}‘|tr "\n" " " `;do brctl show | grep $i >/dev/null; [ "$?" != "0" ] && brctl addif br0 $i;brctl addif br1 ${i}-2;done



less a.sh

#!/bin/bash

cp /etc/network/interfaces /etc/network/interfacesbak

netmasknum=`grep -i -n "netmask" /etc/network/interfaces | awk -F : ‘{print $1}‘|grep -v $(($(grep -i -n "gateway" /etc/network/interfaces|awk -F : ‘{print $1}‘)-1))`

wangkaming=`head -n $(($netmasknum-3)) /etc/network/interfaces|tail -n 1| awk ‘{print $2}‘`

wangkaip=`head -n $(($netmasknum-1)) /etc/network/interfaces | tail -n 1 | awk ‘{print $2}‘`

totalnum=`grep -n -i "post-up" /etc/network/interfaces | awk -F : ‘{print $1}‘`

sed -i `expr $netmasknum + 1`a"auto br1" /etc/network/interfaces

sed -i `expr $netmasknum + 2`a"\\\tiface br1 inet static" /etc/network/interfaces

sed -i `expr $netmasknum + 3`a"\\\taddress ${wangkaip}" /etc/network/interfaces

sed -i `expr $netmasknum + 4`a"\\\tnetmask 255.255.255.0" /etc/network/interfaces

sed -i `expr $netmasknum + 5`a"\\\tbridge_ports ${wangkaming}" /etc/network/interfaces

sed -i `expr $netmasknum + 6`a"\\\tbridge_stp off" /etc/network/interfaces

sed -i `expr $netmasknum + 7`a"\\\tbridge_fd 0" /etc/network/interfaces

sed -i `expr $netmasknum + 8`a"\\\tbridge_maxwait 0" /etc/network/interfaces

sed -i `expr $netmasknum + 9`a"\\\tdns-nameservers 202.106.0.20 202.106.196.115" /etc/network/interfaces

sed -i `expr $netmasknum + 10`a"\\\t" /etc/network/interfaces


sed -i ‘s/\(.*post-up.*\)/#\1/‘ /etc/network/interfaces

sed -i "$(($netmasknum-3)),${netmasknum}d" /etc/network/interfaces

sed -i "s#.*dns-nameservers.*#\\tdns-nameservers 202.106.0.20 202.106.196.115#g" /etc/network/interfaces

cat >> /etc/network/interfaces << "EOF"

       post-up for i in `virsh list | grep running| awk ‘{print $2}‘|tr "\n" " " `;do brctl show | grep $i >/dev/null; [ "$?" != "0" ] && brctl addif br0 $i;brctl addif br1 ${i}-2;done

EOF

本文出自 “freeterman” 博客,请务必保留此出处http://myunix.blog.51cto.com/191254/1410620

对interface文件操作,布布扣,bubuko.com

对interface文件操作

标签:interface   running   gateway   address   null   

原文地址:http://myunix.blog.51cto.com/191254/1410620

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!