Integrates open Vswitch and DNSMASQ to provide DHCP functionality for virtual machines

Source: Internet
Author: User
Tags dns forwarder openvswitch

Following the installation of open VSwitch in the Ubuntu14.04 installation configuration Open VSwitch, here we will create two KVM VMs and automatically assign private IP addresses to these two VMS through DNSMASQ.

The virtual machine and host network structure diagram are as follows:

Test Environment Description:

1) Test private network segment: 172.17.0.0/24

2) Test VLAN tag:100

The following is a brief introduction to the entire configuration process:

1, installation DNSMASQ:

??sudoApt-getInstalldnsmasqreading Package Lists ... Donebuilding Dependency Tree Reading state information ... Donethe following NEW packages 'll be INSTALLED:DNSMASQ0Upgraded,1Newly installed,0To remove andPanax NotoginsengNot upgraded. Need to get14.9KB of archives. After this operation, theKB of additional disk space would be used. Get:1http//cn.archive.ubuntu.com/ubuntu/trusty-updates/universe dnsmasq All 2.68-1ubuntu0.1 [14.9 KB]Fetched14.9Kbinch0s (138kb/s) Selecting previously unselected package dnsmasq. (Reading database ...231198files and directories currently installed.) Preparing to unpack .../dnsmasq_2. the-1ubuntu0.1_all.deb ... Unpacking DNSMASQ (2.68-1ubuntu0.1) ... Processing triggers forUreadahead (0.100.0- -) ... ureadahead'll be reprofiled on next rebootsetting up DNSMASQ (2.68-1ubuntu0.1) ... *starting DNS forwarder and DHCP server dnsmasq [OK] Processing triggers forUreadahead (0.100.0- -) ...?? sudo PS-ea |grepDNS3307?xx:xx:xxDnsmasq

2, create a internal port through OvS, here named Qdhcp, and set VLAN ID 100, for the following DNSMASQ process use:

??  sudo ovs-vsctl add-port br0 qdhcp tag=??   sudo ovs-vsctl set Interface qdhcp type=internal

3. View the QDHCP port you have created:

??sudoovs-Vsctl show1e6548a9-956e-4b86-b743-f8da0aa2b922 Bridge"br0"Port"br0"Interface"br0"type:internal Port qdhcp tag: -Interface qdhcp type:internal Port"eth0"Interface"eth0"ovs_version:"2.0.2"?? ifconfigqdhcp Link encap:ethernet HWaddr the: 6c:a8:c2: -: theInet6 ADDR:FE80::706C:A8FF:FEC2:4868/ -scope:link up broadcast RUNNING MTU: theMetric:1RX Packets:0Errors0Dropped0Overruns:0Frame0TX Packets:7Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen:0RX Bytes:0(0.0B) TX Bytes:578(578.0B

4, to the QDHCP virtual network card configuration IP address, where the IP address must be in the test private network, here we assign 172.17.0.1 to QDHCP:

??sudo ifconfigQdhcp172.17.0.1Netmask255.255.255.0Up ?? ifconfigqdhcp Link encap:ethernet HWaddr the: 6c:a8:c2: -: theinet Addr:172.17.0.1Bcast:172.17.0.255Mask:255.255.255.0Inet6 ADDR:FE80::706C:A8FF:FEC2:4868/ -scope:link up broadcast RUNNING MTU: theMetric:1RX Packets:0Errors0Dropped0Overruns:0Frame0TX Packets:8Errors0Dropped0Overruns:0Carrier0Collisions:0Txqueuelen:0RX Bytes:0(0.0B) TX Bytes:648(648.0B

5, start a DNSMASQ process, monitor the QDHCP virtual network card:

??  sudo /usr/sbin/dnsmasq--strict-order--bind-interfaces--interface=qdhcp--except-interface=lo--pid-  File=/var/run/dnsmasq/qdhcp.pid--leasefile-ro--dhcp-range=172.17. 0.2,172.17. 0.254,255.255. 255.0, 12h--conf-file=

6. View the DNSMASQ process that has been started:

??PSAux |grepDnsmasqnobody3471  0.0  0.0  35228  2412? S A: -   0:xx/USR/SBIN/DNSMASQ--strict-order--bind-interfaces--interface=qdhcp--except-interface=lo--pid-file=/var/run/dnsmasq/qdhcp.pid--leasefile-ro--dhcp-range=172.17.0.2,172.17.0.254,255.255.255.0, 12h--conf-file=

7, the following is the collation of two virtual machine VM1, VM2 configuration file, here only show interface this configuration item:

VM1: <interface type=‘Bridge' > <source bridge=‘Br0'/> <vlan> <tag id= '/> </vlan> <virtualport type='Openvswitch'/><target dev=‘Tap0'/> <model type=‘Virtio'/> </interface>vm2: <interface type=bridge "> <source bridge=  ' br0 "/>  <vlan> <tag id= '/> </vlan>   < Virtualport type= ' Openvswitch '/>   <target dev= tap0  '/> <model type=virtio    

Here, the VLAN ID of the virtual network card for two virtual machines is set to 100, that is, it must be guaranteed and QDHCP port in the same VLAN.

8, start VM1, VM2, and view OvS virtual network card tap0, TAP1 situation:

??sudoovs-Vsctl show1e6548a9-956e-4b86-b743-f8da0aa2b922 Bridge"br0"Port"Tap1"tag: -Interface"Tap1"Port"br0"Interface"br0"type:internal Port qdhcp tag: -Interface qdhcp type:internal Port"eth0"Interface"eth0"Port"tap0"tag: -Interface"tap0"ovs_version:"2.0.2"

As a result, we have VM1, VM2, and QDHCP ports in the same VLAN.

10, through the VNC login to VM1, VM2, to see if it gets to the designated private network segment IP address:

VM1:

VM2:

11. Ping VM2 from VM1:

At this point, the integration of the open Vswitch and DNSMASQ function is complete, two virtual machines can be fun to play.

Integrates open Vswitch and DNSMASQ to provide DHCP functionality for virtual machines

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.