Docker + OpenvSwitch build VxLAN experiment environment, dockervxlan

Source: Internet
Author: User

Docker + OpenvSwitch build VxLAN experiment environment, dockervxlan

I. Overview

1. Environment: I have two linux machines (host1 and host2). The release version is kali2.0 and the kernel version is 4.3. Docker and OpenvSwitch (ovs) are installed on each machine ).

2. host1 and host2 start one ubuntu docker container respectively.

3. Network Structure:

2.1: eth0: 192.168.2.1 for host1, And the IP address of the docker container in host1 is 10.1.2.3

2.2: eth0: 192.168.2.2 of host2, And the IP address of the docker container in host2 is 10.1.2.4

2.3: eth0 of host1 and host2 can be pinged.

4. The goal is to establish a VxLAN tunnel between two docker containers of different hosts so that they can communicate with each other!

2. Install basic software

1. Install docker and obtain the ubuntu Image

1 sudo apt-get install docket.io2 sudo docker pull ubuntu

2. Install docker script for openvswitch and ovs

1 sudo apt-get install openvswitch-switc2 // The secondary script ovs-docker3 wget https://github.com/openvswitch/ovs/raw/master/utilities/ovs-docker4 chmod a + x ovs-Docker supporting docker containers provided by the OpenvSwitch Project

Iii. Configuration

1. Create a virtual bridge with ovs on host1 and give the bridge an ip address

1 sudo ovs-vsctl add-br vxbr2 sudo ifconfig vxbr 10.1.2.1/24

2. Add a vxlan port to the bridge. remote_ip is the eth0 address of host2 !!!

1 sudo ovs-vsctl add-port vxbr vxlan -- set interface vxlan type=vxlan options:remote_ip=192.168.2.2

3. Start a docker container without an Ethernet Card

1 sudo docker run --net=none --privileged=true -it ubuntu

And write down the container ID. Here I am: b062406bc6b6. At this time, only one lo device can be seen in ifconfig in this container.

4. Specify an eth0 for the container and bind it to the vxbr Bridge of the host.

1 sudo ./ovs-docker add-port vxbr eth0 b062406bc6b6

Return to the container, and an eht0 is displayed in ifconfig. Give it an ip Address:

1 ifconfig eth0 10.1.2.3/24

5. View ovs configurations

1 sudo ovs-vsctl show

We can see that there are three ports on the vxbr bridge, one is the port for self-communication with the local machine (eth0 here), and the other is the vxlan port, the last one is the eth0 Of The docker container machine.

The host2 configuration is similar to the above. Change the virtual bridge vxbr of host2 to 10.1.2.2/24, the remote_ip of vxlan to 192.168.2.1 of host1, And the ip address of the docker container machine of host2 to 10.1.2.4/24.

Iv. Verification

The network structure at this time:

The eth0: 192.168.2.1 of host1, the virtual bridge vxbr: 10.1.2.1, And the eth0: 10.1.2.3 Of The docker container machine. The docker container's eth0 is inserted on the virtual bridge vxbr of the host host1.

The eth0: 192.168.2.2 of host2, the virtual bridge vxbr: 10.1.2.2, And the eth0: 10.1.2.4 Of The docker container machine. The docker container's eth0 is inserted on the virtual bridge vxbr of host machine host2.

In the docker container machine of host1, ping the docker container machine of host2 and capture packets with wireshark:

We can see that the communication between container machines is encapsulated in a UDP packet, which is forwarded through the eth0 of host1 and host2.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.