Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2758895
  • 博文数量: 587
  • 博客积分: 6356
  • 博客等级: 准将
  • 技术积分: 6410
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-23 10:54
个人简介

器量大者,福泽必厚

文章分类

全部博文(587)

文章存档

2019年(3)

2018年(1)

2017年(29)

2016年(39)

2015年(66)

2014年(117)

2013年(136)

2012年(58)

2011年(34)

2010年(50)

2009年(38)

2008年(16)

分类: LINUX

2012-08-09 17:10:00

With bridged networking you can share actual network device with KVM machines. This is required for servers with multiple network cards and gives you good performance. You can choose to put multiple segments into one bridged network or to divide it into different networks interconnected by routers
.老外的一篇文章! 写的很详细!


Our Sample Setup:

The following describes the networking used by our setup:


  • All other clients can reached to all VMs via br1 which is connected to public interface. br1 is our default gateway.
  • br0 is connected to private LAN to access other servers, services and storage devices such as SAN/NAS or NFS servers. br0 route is configured via route-br0 static networking configuration file.
Turn Off NetworkManager


The NetworkManager (GUI) tool can create problems with bridged based networking so disable it as follows, enter:
# chkconfig NetworkManager off
# chkconfig network on
# service NetworkManager stop


Edit /etc/sysconfig/network, enter:
# vi /etc/sysconfig/network
Update file as follows:

NETWORKING=yes 

HOSTNAME=kvm42.nixcraft.net
GATEWAY=br1  

Save and close the file.

br0: Configure Bridging for eth0

Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Update it as follows:

DEVICE=eth0
ONBOOT=yes 
ETHTOOL_OPTS="autoneg off speed 100 duplex full"
BRIDGE=br0 ##添加的一行
HWADDR=b8:ac:6f:65:31:e5    

Save and close the file.

 Create /etc/sysconfig/network-scripts/ifcfg-br0, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-br0
Update it as follows (note options are case sensitive i.e. Bridge and bridge are two different options)

DEVICE=br0 
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes 
IPADDR=10.10.21.70 
NETMASK=255.255.255.192
DELAY=0  

Save and close the file.

 Finally, create static routing file /etc/sysconfig/network-scripts/route-br0, enter :
# vi /etc/sysconfig/network-scripts/route-br0
Edit it as follows:

10.0.0.0/8 via 10.10.21.122 dev br0

Save and close the file. Delete old /etc/sysconfig/network-scripts/route-eth0 (if exists):
# rm /etc/sysconfig/network-scripts/route-eth0

br1: Configure Bridging for eth1

Edit /etc/sysconfig/network-scripts/ifcfg-eth1, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-eth1
Update it as follows:

DEVICE=eth1
ONBOOT=yes
ETHTOOL_OPTS="autoneg off speed 100 duplex full"
BRIDGE=br1
HWADDR=00:30:49:8c:48:ad    

Please note that test server is set to 100Mbps full duplex. Save and close the file.

Edit /etc/sysconfig/network-scripts/ifcfg-br1, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-br1
Define public IP address including gateway as follows:

DEVICE=br1
BOOTPROTO=static 
ONBOOT=yes 
IPADDR=123.1.2.3 
NETMASK=255.255.255.248
GATEWAY=123.1.2.200
TYPE=Bridge 
DELAY=0  

Save and close the file.

Restart Network Service

Type the following command:
# service network restart
Make sure everything is working fine:
# brctl show
Sample outputs:

bridge name   bridge id        STP     enabled interfaces 
br0      8000.0030488e31ac     no      eth0 
br1      8000.0030488e31ad     no      eth1
virbr0   8000.000000000000     yes


 

Verify IPs and routing tables:
# ip addr show br0
# ip addr show br1
# ip route
# ping cyberciti.biz ##确认网络是否通!
# host google.com


另外一篇讲述KVM 网络的文章!

在Redhat Enterprise Linux 5 (RHEL5)上设置KVM虚拟机时有两种网络选项:

  1. 1. Virtual network
  2. 2.Shared physical device
  3. 但预设的只有 Virtual network.在RHEL5 KVM 的环境预设会建立一个 bridge,由 QEMU 所提供出的 virbr0 预设安装 Virtual machine 时网络卡的选择也就是这种 Virtual network .
  • 一:Virtual network - virbr0
  • 1.QEMU 会在你的 Linux 产生一个 bridge 虚拟装置 "virbr0" .virbr0 不只是个单纯的 NAT 而已,他是一个 NAT + DHCP 的架构,所有的 Virtual machine 都会透过 virbr0 来指派一个私人网域 (private IP).预设为 192.168.122.2 ~ 192.168.122.254 (在他的设定档中可以定义其 DHCP 可指定的 IP 范围).
  • ip范围设置在:

  • [root@host1 networks]# pwd
  • /etc/libvirt/qemu/networks
  • [root@host1 networks]# cat default.xml 
  •   default
  •   d8fc074a-7abe-40f9-b1c3-c46ed8a1e296
  •  
  •  
  •  
  •    
  •      
  •    
  •  
  • 见附件
  1. 2.其预设的 default gateway 为 192.168.122.1/24 ,所有在这架构下的 Virtual Machine 虚拟机器的封包都必须透过这 NAT 去连结到其它的网络.

  2. 3. 如同一般的 NAT 所有的 Virtual Machine 虚拟机器都是被隐藏在 private私有网络,所以外部不能直接连接到 Virtual Machine 虚拟机器上.
  1. 二:Shared physical device
  2.    如果要使用第二种 "Shared physical device" 时需要经过手动设定才能使用.此时所有的 Virtual machine 的网络装置就会像是串接在一个 Hub 或是 Switch 上,只要是同区段的 IP 都可以互通. 在Linux下网络的模式有一种叫做 Bridge mode,有点像将多个 NIC Adapter ports 透过一个虚拟出来的 Bridge(Switch) 全部串在一起,再透过一个虚拟出来的网络装置出去,这就像是把 Linux 当成一个 switch 来使用了.在一般的 Linux 环境下的方法也很简单:我们也可以透过下面几个简单的指令来产生自己所需要的 Bridge 装置出来.下面的图示你可以很清楚的看出来虚拟 NIC 和实体 NIC 是如何透过 bridge 模式串接在一起.


另外一部分介绍:

1.桥模式简介
关于桥的模式:
其实我们在虚拟机搭建的时候,我们最终关心的网卡是: eth0, br0, vnet0,vnet1… 其中,
我们的eth0是原来的物理网卡,br0是我们虚拟出来的桥设备,而vnetXXX就是桥接映射到虚拟机里面用到的网卡。
当配置完了之后,我们使用ifconfig,查看起来的话,eth0是没有ip地址的,而br0仿佛是虚拟出来的一个原来eth0的访问接口,
它具有ip地址,可以代替原来的eth0被访问,而vnetXX的地址可以在建立虚拟机之后在虚拟机里面配置
,桥接后可以被外部访问。


brctl addbr br0      # 创建一个桥接口
brctl addif br0 eth0 # 添加eth0到br0,


在安装KVM的时候,系统会自动安装virbr0这个设备的,这个设备在使用NAT模式才会用到,这里我们使用的桥接模式,其实是可以将它删除掉
brctl delbr virbr0 如果显示在用的话,就要先ifconfig virbr0 down将该网桥停掉,然后再删除!



阅读(1712) | 评论(0) | 转发(3) |
给主人留下些什么吧!~~