KVM之Vlan实验
时间:2020-04-20 11:23 来源:51cto.com 作者:51cto.com
逻辑图:
[需求]:
在KVM主机上有若干台虚拟机,它们分别属与不同的vlan,如上图的vlan10,vlan20,我们现在想实现vlan之间互通.
[实验步骤如下]
添加KVM主机vlan
more /etc/rc.local
modprobe 8021q
vconfig add em2 10
vconfig add em2 20
ifconfig em2.10 up
ifconfig em2.20 up
brctl addbr br10
brctl addbr br20
ifconfig br10 up
ifconfig br20 up
brctl addif br10 em2.10
brctl addif br20 em2.20
启动虚拟机后将虚拟机生产的逻辑网口vnet0,vnet1分别加入到不同的vlan中.
brctl addif br10 vnet0
brctl addif br20 vnet1
虚拟机配置不同的网段,如:
Vm1:192.10.10.30
Vm2:192.20.20.30
此时:
需要配置交换机(3750)
Kvm-vlan(config)#vlan database
Kvm-vlan(vlan)#vlan 10
Kvm-vlan(vlan)#vlan 20
Kvm-vlan(vlan)#exit
Kvm-vlan(config)#int vlan 10
Kvm-vlan(config-if)#ip address 192.10.10.1 255.255.255.0
Kvm-vlan(config)#int vlan 20
Kvm-vlan(config-if)#ip address 192.20.20.1 255.255.255.0
Kvm-vlan(config-if)#int fa 1/0/3
Kvm-vlan(config-if)#switchport trunkencapsulation dot1q
Kvm-vlan(config-if)#switchport mode trunk
Kvm-vlan(config-if)#no shut
Kvm-vlan(config)#ip routing
此时再在虚拟机之间互ping,可通!
技巧:
1.删除vlan
ifconfig em2.10 down
vconfig rem em2.10
2.将vlan配置添加到配置文件中
[root@localhost network-scripts]# more ifcfg-em2
DEVICE="em2"
HWADDR="D4:BE:D9:B5:BC:21"
ONBOOT="yes"
TYPE="Ethernet"
UUID="fc9a6ac1-7850-4ba6-aced-e8aa1813869e"
[root@localhost network-scripts]# more ifcfg-em2.10
DEVICE="em2.10"
VLAN=yes
ONBOOT="yes"
TYPE="Ethernet"
BRIDGE=br10
[root@localhost network-scripts]# more ifcfg-em2.20
DEVICE="em2.20"
VLAN=yes
ONBOOT="yes"
TYPE="Ethernet"
BRIDGE=br20
[root@localhost network-scripts]# more ifcfg-br10
DEVICE=br10
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
DELAY=0
[root@localhost network-scripts]# more ifcfg-br20
DEVICE=br20
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
DELAY=0
(责任编辑:IT)
逻辑图:
[需求]: 在KVM主机上有若干台虚拟机,它们分别属与不同的vlan,如上图的vlan10,vlan20,我们现在想实现vlan之间互通.
[实验步骤如下] 添加KVM主机vlan
more /etc/rc.local modprobe 8021q
vconfig add em2 10 vconfig add em2 20 ifconfig em2.10 up ifconfig em2.20 up brctl addbr br10 brctl addbr br20 ifconfig br10 up ifconfig br20 up brctl addif br10 em2.10 brctl addif br20 em2.20 启动虚拟机后将虚拟机生产的逻辑网口vnet0,vnet1分别加入到不同的vlan中. brctl addif br10 vnet0 brctl addif br20 vnet1
虚拟机配置不同的网段,如: Vm1:192.10.10.30 Vm2:192.20.20.30
此时: 需要配置交换机(3750) Kvm-vlan(config)#vlan database Kvm-vlan(vlan)#vlan 10 Kvm-vlan(vlan)#vlan 20 Kvm-vlan(vlan)#exit Kvm-vlan(config)#int vlan 10 Kvm-vlan(config-if)#ip address 192.10.10.1 255.255.255.0
Kvm-vlan(config)#int vlan 20 Kvm-vlan(config-if)#ip address 192.20.20.1 255.255.255.0
Kvm-vlan(config-if)#int fa 1/0/3 Kvm-vlan(config-if)#switchport trunkencapsulation dot1q Kvm-vlan(config-if)#switchport mode trunk Kvm-vlan(config-if)#no shut
Kvm-vlan(config)#ip routing
此时再在虚拟机之间互ping,可通!
技巧: 1.删除vlan ifconfig em2.10 down vconfig rem em2.10 2.将vlan配置添加到配置文件中
(责任编辑:IT) |