OVS 配置虚机vlan

OVS 配置虚机vlan

测试环境:

网络:vlan100, 192.168.100.0/24
vlan101, 192.168.101.0/24
宿主系统:CentOS-7.2 64bit
宿主IP:192.168.100.33
宿主网卡:eth0, 对应交换机端口trunks[100, 101], pvid 100
待配置虚机IP:192.168.100.34, 192.168.101.34

操作

1.修改/etc/sysconfig/network-scripts/ifcfg-eth0;

DEVICE="eth0"
ONBOOT="yes"
NM_CONTROLLED="no"

2.增加/etc/sysconfig/network-scripts/ifcfg-ovsbr0;

DEVICE="ovsbr0"
IPADDR="192.168.100.33"
NETMASK="255.255.255.0"
ONBOOT="yes"
BOOTPROTO="static"
TYPE="Ethernet"
NM_CONTROLLED="no"

3.重启网络;

service network restart

4.增加ovsbr0网桥

ovs-vsctl add-br ovsbr0
ovs-vsctl add-port ovsbr0 eth0

5.配置端口eth0

ovs-vsctl set port eth0 trunks=0,100,101

6.配置虚机
虚机有两种配置方案
+虚机内两个网卡eht0, eth1

<interface type='bridge'>
    <source bridge='ovsbr0'/>
    <virtualport type='openvswitch'/>
    <target dev='vnet0'/>
    <model type='virtio'/>
interface>
<interface type='bridge'>
    <source bridge='ovsbr0'/>
    <virtualport type='openvswitch'/>
    <target dev='vnet1'/>
    <model type='virtio'/>
interface>

此时虚机eth0网卡对应vnet0, ip 192.168.100.34; eth1对应vnet1, ip 192.168.101.34;

ovs-vsctl set port vnet0 vlan_mode=access
ovs-vsctl set port vnet0 tag=0
ovs-vsctl set port vnet1 vlan_mode=access
ovs-vsctl set port vnet1 tag=101

这里将vnet0 tag设置为0,因为在物理交换机端口将pvid设置为100,到达宿主内tag为100的包已经被解掉tag,所以这里设为0。
+虚机内一个网卡eth0,和一个vlan网卡eth0.101

<interface type='bridge'>
    <source bridge='ovsbr0'/>
    <virtualport type='openvswitch'/>
    <target dev='vnet0'/>
    <model type='virtio'/>
interface>

此时虚机eth0网卡对应vnet0, ip 192.168.100.34, 192.168.101.34;

ovs-vsctl set port vnet0 vlan_mode=trunk
ovs-vsctl set port vnet0 trunks=0,101

7.虚机内配置路由即可通路。

你可能感兴趣的:(SDN及网络,虚拟化和云计算)