首页 文章

连接open vswitch和两个虚拟机

提问于
浏览
1

我在VirtualBox VM上运行Open VSwitch,我想将在VirtualBox上运行的2个VM连接到OpenVswitch . 我做了这些事情:

1)首先我创建了一个运行ubuntu(lubuntu)的VM,并使用以下命令安装ovs

sudo apt-get install openvswitch-switch

2)之后我在vm上定义了2个适配器并确定它们为 Internal Network 因为vms想要从虚拟盒内部连接到这些机器

但是如何使用此OVS连接2个运行在不同子网( 10.1.1.1 and 10.1.2.1 )上的虚拟机的VM?该图如下:http://www.gliffy.com/go/publish/image/10986491/L.png

1 回答

  • 3

    我不认为你需要在这种情况下使用OVS,尽管你可以通过提供网关ip来实现这一点 .

    enter image description here

    假设您已创建内部网络,子网192.170.10.0/24为internal1,其他internal2为子网192.170.20.0/24

    Configuration on VM1:

    auto eth0
    iface eth0 inet static
    address 192.170.10.10
    network 192.170.10.0
    netmask 255.255.255.0
    broadcast 192.170.10.255
    gateway 192.170.10.20
    

    Configuration on VM2:

    auto eth0
    iface eth0 inet static
    address 192.170.20.10
    network 192.170.20.0
    netmask 255.255.255.0
    broadcast 192.170.20.255
    gateway 192.170.20.20
    

    Configuration on OVS:

    auto eth0
    iface eth0 inet static
    address 192.170.10.20
    network 192.170.10.0
    netmask 255.255.255.0
    broadcast 192.170.10.255
    gateway 192.170.10.20
    
    auto eth1
    iface eth1 inet static
    address 192.170.20.20
    network 192.170.20.0
    netmask 255.255.255.0
    broadcast 192.170.20.255
    gateway 192.170.20.20
    

    使用上述配置,您可以在不同子网上的VM之间执行ping操作


    但是,如果您仍想使用OVS,则可以使用以下方法进行配置 .

    Configuration on VM1:

    auto eth0
    iface eth0 inet static
    address 192.170.10.10
    network 192.170.10.0
    netmask 255.255.255.0
    broadcast 192.170.10.255
    

    Configuration on VM2:

    auto eth0
    iface eth0 inet static
    address 192.170.20.10
    network 192.170.20.0
    netmask 255.255.255.0
    broadcast 192.170.20.255
    

    Configuration on OVS:

    • /etc/network/interfaces 中将接口设置为手动加载
    auto eth0
    iface eth0 inet manual
    
    auto eth1
    iface eth1 inet manual
    
    • 创建两个桥梁
    sudo ovs-vsctl add-br vm1-br
    sudo ovs-vsctl add-br vm2-br
    
    • 添加相应的端口 .
    sudo ovs-vsctl add-port vm1-br eth0
    sudo ovs-vsctl add-port vm2-br eth1
    
    • 使用补丁接口桥接桥接器
    sudo ovs-vsctl add-port vm1-br patch1
    sudo ovs-vsctl set interface patch1 type=patch
    sudo ovs-vsctl set interface patch1 options:peer=patch2
    
    sudo ovs-vsctl add-port vm1-br patch2
    sudo ovs-vsctl set interface patch2 type=patch
    sudo ovs-vsctl set interface patch2 options:peer=patch1
    
    • 建起桥梁
    sudo ifconfig vm1-br up
    sudo ifconfig vm-br up
    
    • 设置IP地址
    sudo ifconfig vm1-br 192.170.10.20/24
    sudo ifconfig vm2-br 192.170.20.20/24
    
    • 现在您可以在VM之间执行ping操作

相关问题