KVM Bonding Vlan Bridge功能测试
名称 |
ip |
说明 |
Vm1 |
192.10.10.62 |
虚拟机vlan100 |
Vm2 |
192.20.20.61 |
虚拟机vlan101 |
Vlan100 |
192.10.10.1 |
交换机vlan100 |
Vlan101 |
192.20.20.1 |
交换机vlan101 |
Server |
192.10.10.64 |
测试机 |
拓扑
服务器配置
[root@kvm network-scripts]# more/etc/sysconfig/network
HOSTNAME=kvm.example.com
NETWORKING=yes
# IPv4
NETWORKING=yes
NOZEROCONF=yes
# IPv6, necessary for bonding
NETWORKING_IPV6=yes
IPV6INIT=yes
[root@kvm network-scripts]# more/etc/modprobe.d/bonding.conf
alias bond0 bonding
[root@kvm network-scripts]# more ifcfg-em2
BOOTPROTO=none
DEVICE=em2
HWADDR=d4:be:d9:b5:bc:21
MASTER=bond0
## Optional, use for jumbo frames if needed
#MTU=9000
NM_CONTROLLED=no
NOZEROCONF=yes
ONBOOT=yes
SLAVE=yes
TYPE=Ethernet
[root@kvm network-scripts]# more ifcfg-em3
BOOTPROTO=none
DEVICE=em3
HWADDR=d4:be:d9:b5:bc:23
MASTER=bond0
## Optional, use for jumbo frames if needed
#MTU=9000
NM_CONTROLLED=no
NOZEROCONF=yes
ONBOOT=yes
SLAVE=yes
TYPE=Ethernet
[root@kvm network-scripts]# more ifcfg-bond0
# Use tagged VLANs
#ARP=no
BOOTPROTO=none
DEVICE=bond0
IPV6INIT=no
## Optional, use for jumbo frames if needed
#MTU=9000
NM_CONTROLLED=no
NOZEROCONF=yes
ONBOOT=yes
BONDING_OPTS="mode=4 miimon=100"
[root@kvm network-scripts]# more ifcfg-bond0.100
DEVICE=bond0.100
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
VLAN=yes
BRIDGE=br100
[root@kvm network-scripts]# more ifcfg-bond0.101
DEVICE=bond0.101
ONBOOT=yes
TYPE=Ethernet
BOOTPROTO=static
VLAN=yes
BRIDGE=br101
[root@kvm network-scripts]# more ifcfg-br100
DEVICE=br100
ONBOOT=yes
SLAVE=bond0.100
TYPE=Bridge
VLAN=yes
# IPv4
#GATEWAY=192.10.10.1
#IPADDR=192.10.10.2
#NETMASK=255.255.255.0
NM_CONTROLLED=no
NOZEROCONF=yes
## Optional, use for jumbo frames if needed
#MTU=9000
# IPv6
#IPV6ADDR=
#IPV6ADDR_SECONDARIES=
#IPV6_AUTOCONF=no
#IPV6_MTU=9000
[root@kvm network-scripts]# more ifcfg-br101
DEVICE=br101
ONBOOT=yes
SLAVE=bond0.101
TYPE=Bridge
VLAN=yes
# IPv4
# Usually only one gateway is configured
#GATEWAY=192.20.20.1
#IPADDR=192.20.20.2
#NETMASK=255.255.255.0
NM_CONTROLLED=no
NOZEROCONF=yes
## Optional, use for jumbo frames if needed
#MTU=9000
# IPv6
#IPV6ADDR=
#IPV6ADDR_SECONDARIES=
#IPV6_AUTOCONF=no
#IPV6_MTU=9000
3550交换机配置:
添加vlan100,vlan101两个svi ip以供虚拟机作为网关.
Kvm-vlan#vlandata
Kvm-vlan(vlan)#vlan100
VLAN100 added:
Name: VLAN0100
Kvm-vlan(vlan)#vlan101
VLAN101 added:
Name: VLAN0101
Kvm-vlan(config)#int vlan 100
Kvm-vlan(config-if)#ip add
Kvm-vlan(config-if)#ip address 192.10.10.1255.255.255.0
Kvm-vlan(config-if)#int vlan 101
Kvm-vlan(config-if)#ip address 192.20.20.1255.255.255.0
Kvm-vlan(config-if)#
将server机器添加到vlan100中
Kvm-vlan(config)#int fa 1/0/10
Kvm-vlan(config-if)#switchport access vlan 100
将两块kvm机器的网卡绑定到port-channel中,并且开启trunk.
Kvm-vlan(config-if)#int fa 1/0/3
Kvm-vlan(config-if)#channel-group 1 mode active
Creating a port-channel interface Port-channel 1
Kvm-vlan(config-if)#switchport trunk encapsulationdot1q
Kvm-vlan(config-if)#switchport mode trunk
Kvm-vlan(config-if)#int fa 1/0/7
Kvm-vlan(config-if)#channel-group 1 mode active
Kvm-vlan(config-if)#switchport trunk encapsulationdot1q
Kvm-vlan(config-if)#switchport mode trunk
开启路由:
Kvm-vlan(config)#ip routing
交换机检查:
Kvm-vlan(config-if)#do sh eth sum
Flags:D -downP - in port-channel
I -stand-alone s - suspended
H -Hot-standby (LACP only)
R -Layer3S - Layer2
U - inusef - failed to allocateaggregator
u -unsuitable for bundling
w - waiting to be aggregated
d -default port
Number of channel-groups in use: 1
Number of aggregators:1
GroupPort-channelProtocolPorts
------+-------------+-----------+-----------------------------------------------
1Po1(SU)LACPFa1/0/3(P)Fa1/0/7(P)
Kvm-vlan(config-if)#do sh run
Building configuration...
Current configuration : 2006 bytes
!
version 12.2
no service pad
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname Kvm-vlan
!
enable secret 5 $1$JKxo$gZlTPxmXBNMz5lyompQWD.
!
username badboy secret 5$1$ihuM$czIafVPxsOzRxCMZo/dzt1
no aaa new-model
switch 1 provision ws-c3750-24ts
system mtu routing 1998
ip subnet-zero
ip routing
!
!
!
!
no file verify auto
spanning-tree mode pvst
spanning-tree extend system-id
!
vlan internal allocation policy ascending
!
interface Port-channel1
switchport trunk encapsulation dot1q
switchport mode trunk
!
interface FastEthernet1/0/1
!
interface FastEthernet1/0/2
!
interface FastEthernet1/0/3
switchport trunk encapsulation dot1q
switchport mode trunk
channel-group 1 mode active
!
interface FastEthernet1/0/4
!
interface FastEthernet1/0/5
!
interface FastEthernet1/0/6
!
interface FastEthernet1/0/7
switchport trunk encapsulation dot1q
switchport mode trunk
channel-group 1 mode active
!
interface FastEthernet1/0/8
!
interface FastEthernet1/0/9
switchport modeaccess
!
interface FastEthernet1/0/10
switchport access vlan 100
switchport mode access
!
检查结果:
[root@kvm network-scripts]# ifconfig
bond0Link encap:EthernetHWaddrD4:BE:D9:B5:BC:21
inet6 addr: fe80::d6be:d9ff:feb5:bc21/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICASTMTU:1500Metric:1
RX packets:152605 errors:0 dropped:0 overruns:0 frame:0
TX packets:1695 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:36780655 (35.0 MiB)TXbytes:179888 (175.6 KiB)
bond0.100 Link encap:EthernetHWaddr D4:BE:D9:B5:BC:21
inet6 addr: fe80::d6be:d9ff:feb5:bc21/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICASTMTU:1500Metric:1
RX packets:4211 errors:0 dropped:0 overruns:0 frame:0
TX packets:978 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:236962 (231.4 KiB)TXbytes:88016 (85.9 KiB)
bond0.101 Link encap:EthernetHWaddr D4:BE:D9:B5:BC:21
inet6 addr: fe80::d6be:d9ff:feb5:bc21/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICASTMTU:1500Metric:1
RX packets:3490 errors:0 dropped:0 overruns:0 frame:0
TX packets:249 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:177226 (173.0 KiB)TXbytes:20314 (19.8 KiB)
br0Link encap:EthernetHWaddrD4:BE:D9:B5:BC:1F
inet addr:192.168.x.xx Bcast:192.168.x.xx Mask:255.255.255.0
inet6 addr: fe80::d6be:d9ff:feb5:bc1f/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:123803 errors:0 dropped:0 overruns:0 frame:0
TX packets:13917 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:13331260 (12.7 MiB)TXbytes:14767233 (14.0 MiB)
br100Link encap:EthernetHWaddrD4:BE:D9:B5:BC:21
inet6 addr: fe80::d6be:d9ff:feb5:bc21/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:3457 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:171976 (167.9 KiB)TXbytes:468 (468.0 b)
br101Link encap:EthernetHWaddrD4:BE:D9:B5:BC:21
inet6 addr: fe80::d6be:d9ff:feb5:bc21/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:3406 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:170266 (166.2 KiB)TXbytes:468 (468.0 b)
em1Link encap:EthernetHWaddrD4:BE:D9:B5:BC:1F
inet6 addr: fe80::d6be:d9ff:feb5:bc1f/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:165765 errors:0 dropped:0 overruns:0 frame:0
TX packets:21649 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:39556560 (37.7 MiB)TXbytes:15373417 (14.6 MiB)
em2Link encap:EthernetHWaddrD4:BE:D9:B5:BC:21
UP BROADCAST RUNNING SLAVE MULTICASTMTU:1500Metric:1
RX packets:77694 errors:0 dropped:0 overruns:0 frame:0
TX packets:919 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:14304508 (13.6 MiB)TXbytes:94332 (92.1 KiB)
em3Link encap:EthernetHWaddrD4:BE:D9:B5:BC:21
UP BROADCAST RUNNING SLAVE MULTICASTMTU:1500Metric:1
RX packets:74911 errors:0 dropped:0 overruns:0 frame:0
TX packets:776 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:22476147 (21.4 MiB)TXbytes:85556 (83.5 KiB)
em4Link encap:EthernetHWaddrD4:BE:D9:B5:BC:25
UP BROADCAST MULTICASTMTU:1500Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b)TX bytes:0(0.0 b)
vnet0Link encap:EthernetHWaddrFE:54:00:F8:90:32
inet6 addr: fe80::fc54:ff:fef8:9032/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:318 errors:0 dropped:0 overruns:0 frame:0
TX packets:3847 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:29374 (28.6 KiB)TXbytes:255704 (249.7 KiB)
vnet1Link encap:EthernetHWaddrFE:54:00:6E:CE:45
inet6 addr: fe80::fc54:ff:fe6e:ce45/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500Metric:1
RX packets:667 errors:0 dropped:0 overruns:0 frame:0
TX packets:4120 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:62840 (61.3 KiB)TXbytes:283110 (276.4 KiB)
[root@kvm network-scripts]# brctl show
bridge namebridge idSTP enabledinterfaces
br08000.d4bed9b5bc1fnoem1
br1008000.d4bed9b5bc21nobond0.100
vnet0
br1018000.d4bed9b5bc21nobond0.101
vnet1
virbr08000.525400fa9bf8yesvirbr0-nic
[root@kvm network-scripts]# more/proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.6.0(September 26, 2009)
Bonding Mode: IEEE 802.3ad Dynamic linkaggregation
Transmit Hash Policy: layer2 (0)
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
802.3ad info
LACP rate: slow
Aggregator selection policy (ad_select):stable
Active Aggregator Info:
Aggregator ID: 2
Number of ports: 2
Actor Key: 9
Partner Key: 1
Partner Mac Address: 00:1e:be:67:1f:80
Slave Interface: em2
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count: 0
Permanent HW addr: d4:be:d9:b5:bc:21
Aggregator ID: 2
Slave queue ID: 0
Slave Interface: em3
MII Status: up
Speed: 100 Mbps
Duplex: full
Link Failure Count:0
Permanent HW addr: d4:be:d9:b5:bc:23
Aggregator ID: 2
Slave queue ID: 0
[root@kvm network-scripts]# more/proc/net/vlan/bond0.100
bond0.100VID: 100REORDER_HDR: 1dev->priv_flags: 2001
total frames received5987
total bytes received326006
Broadcast/Multicast Rcvd5162
total frames transmitted1050
total bytes transmitted92984
total headroom inc0
total encap on xmit0
Device: bond0
INGRESS priority mappings: 0:01:02:03:04:05:06:0 7:0
EGRESS priority mappings:
[root@kvm network-scripts]# more/proc/net/vlan/bond0.101
bond0.101VID: 101REORDER_HDR: 1dev->priv_flags: 2001
total frames received5277
total bytes received266776
Broadcast/Multicast Rcvd5163
total frames transmitted1002
total bytes transmitted62092
total headroom inc0
total encap on xmit0
Device: bond0
INGRESS priority mappings: 0:01:02:03:04:05:06:0 7:0
EGRESS priority mappings:
测试:
Vm2去ping vlan100下的server机器
从以上,可以看出我们实现了kvm下的bondig mode=4功能,并且采用了vlan隔离.
如果想了解更多,请关注我们的公众号
公众号ID:opdevos
扫码关注