KVM Network Bridging

from http://hzqtc.github.io/2012/02/kvm-network-bridging.html

http://wiki.ubuntu.org.cn/Kvm_%E7%BD%91%E7%BB%9C%E6%A1%A5%E6%8E%A5%E6%96%B9%E6%A1%88

http://lilinji.blog.51cto.com/5441000/1264307

https://help.ubuntu.com/community/KVM/Networking

 

 

As many other hypervisors, KVM provide several types of networking. KVM use NAT in default, in which case the guest can reach the outside world (the host and all place the host can reach) but the outside world cannot reach the guest. That means, if you don’t need to access the guest through network (SSH for example), NAT is good enough for you. However, if you want more, let me introduce you the bridging way.

Concept

In a typical bridged network environment, all guest are connected to a virtual bridge. A host network interface is also connected to the bridge. The packets are forwarded to the guests based on their MAC address, just like any other bridges. In more detai, each guest has a corresponding tap device in the host. These tap devices are both connected to the bridge and the guest, as a network channel.

 

桥接基本原理:

eth0(本地物理网卡)<---br0(桥)--->tap0,tap1….(tap是给kvm guest使用的接口)

1、创建桥
#一般一个机器一个桥即可
sudo brctl addbr br0

2、创建若干tap,KVM需要几个虚拟网卡,就几个
sudo tunctl -t tap0 -u liheyuan
sudo tunctl -t tap1 -u liheyuan
……

3、把eth0,tapX绑定到br0上,eth0肯定要绑定 不然没法上网,tap若干个绑定
sudo brctl addif br0 eth0
sudo brctl addif br0 tap0
sudo brctl addif br0 tap1
……

4、把br0设置成原来eth0的IP,eth0设置为混杂模式
sudo ifconfig br0 192.168.1.33
sudo ifconfig eth0 0.0.0.0 promisc

5、启动所有的tapX,br0是默认启动的,tapX不是
sudo ifconfig tap0 up
sudo ifconfig tap1 up
……

6、修改默认网关改默认网关,不然只能内网通信!
sudo route add -net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1

6、KVM启动
#tap0 guest的eth0
-net nic,name=k1,macaddr=00:11:22:33:66:55
-net tap,vlan=0,name=k1,ifname=tap0,script=no,downscript=no
#tap1 guest的eth1
-net nic,name=k2,macaddr=00:11:22:33:66:56
-net tap,vlan=0,name=k2,ifname=tap1,script=no,downscript=no

--------------------------------------------------------------------------------------------------------------------------------------------

KVM桥接网络的方法:大部分不能桥接无线网卡。。。只能桥接PCI网卡。



 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值