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

KVM网络TAP设置

时间:2017-04-16 23:18:48      阅读:471      评论:0      收藏:0      [点我收藏+]

标签:qemu tap

qemu-ifup

#! /bin/sh
# Script to bring a network (tap) device for qemu-kvm up
# The idea is to add the tap device to the same bridge
# as we have default routing to.
# in order to be able to find brctl
PATH=$PATH:/sbin:/usr/sbin
ip=$(which ip)
if [ -n "$ip" ]; then
   ip link set "$1" up
else
   ifconfig "$1" 0.0.0.0 up
fi
brctl=$(which brctl)
if [ ! "$ip" -o ! "$brctl" ]; then
   echo "W: $0: not doing any bridge processing: ip or brctl utility not found" >&2
   exit 0
fi
switch=$(ip route ls |     awk ‘/^default / {
          for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
         }‘
        )
# only add the interface to default-route bridge if we
# have such interface (with default route) and if that
# interface is actually a bridge.
# It is possible to have several default routes too
for br in $switch; do
    if [ -d /sys/class/net/$br/bridge/. ]; then
        brctl addif $br "$1"
        exit    # exit with status of brctl
    fi
done
echo "W: $0: no bridge for guest interface found" >&2


KVM网络TAP设置

标签:qemu tap

原文地址:http://btvnlue.blog.51cto.com/9578271/1916455

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