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网卡。



 

原文地址:https://www.cnblogs.com/kex1n/p/5229236.html