HowTo Enable DHCP Service Over Docker Container (MLNX-OS)

Version 4

    This post demonstrates how to enable DHCP service over docker container invoked within MLNX-OS.

     

    References

     

    Setup

    In this solution, we configure docker over MLNX-OS and enable DHCP service. In addition, we would need to enable DHCP relay on the IP interface (e.g. VLAN interface or router port) that is connected to the server so the DHCP broadcast messages reach the docker interface.

     

     

     

     

     

    Configuration

    DHCP Daemon on Docker

    1. Follow Getting Started with Docker Container over MLNX-OS , to create a container.

     

    2. Enter the container Linux shell:

    # docker exec my-container "bin/bash"

    Running exec_name:[bin/bash]

     

    3. Install the DHCP package:

    # yum install -y dhcp

     

    4. Set the dhcp.conf file according to the network configuration.

     

    Note: The DHCP daemon looks for a local interface with an IP address in the subnet defined. In this example we will use the IP interface 1.1.6.1  defined on the port connected to the server. Therefore we will enable dynamic range for that subnet.

     

    Create a file called dhcp.conf, and add the following lines based on the switch IP configuration.

    This is a simple example with one subnet.

    subnet 1.1.6.0 netmask 255.255.255.0 {

    range 1.1.6.2 1.1.6.254;

    }

     

    Other DHCP configuration can be configured based on the network needs.

     

    5. Run the DHCP daemon:

    # dhcpd -cf dhcp.conf

    Internet Systems Consortium DHCP Server 4.2.5

    Copyright 2004-2013 Internet Systems Consortium.

    All rights reserved.

    For info, please visit https://www.isc.org/software/dhcp/

    Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file

    Wrote 1 leases to leases file.

     

    No subnet declaration for loopback1 (127.1.1.14).

    ** Ignoring requests on loopback1.  If this is not what

       you want, please write a subnet declaration

       in your dhcpd.conf file for the network segment

       to which interface loopback1 is attached. **

     

    Listening on LPF/swid0_eth.6/24:8a:07:80:54:01/1.1.6.0/24

    Sending on   LPF/swid0_eth.6/24:8a:07:80:54:01/1.1.6.0/24

     

    ...

     

    Make sure that the daemon is listening on the relevant interface.

     

    DHCP Relay on MLNX-OS

    Set up DHCP relay service on MLNX-OS. This is an important step as the DHCP broadcast messages should cross the router to reach the docker interface.

     

    1. Enable DHCP relay:

    switch (config) # ip dhcp relay instance 1 vrf default

    switch (config) # ip dhcp relay instance 1 vrf-auto-helper

    switch (config) # ip dhcp relay instance 1 always-on

     

    2. Set the address of the docker interface acting as the DHCP server:

    switch (config) # ip dhcp relay instance 1 address 172.17.0.1

     

    Network Interface Configuration on the Server

     

    1. On the server, it is necessary to configure the network interface (e.g. eth2) to boot from DHCP.

     

    # cat /etc/sysconfig/network-scripts/ifcfg-eth2

    NAME=eth2

    DEVICE=eth2

    ONBOOT=yes

    NETBOOT=yes

    BOOTPROTO=dhcp

    TYPE=Ethernet

     

    2. Reload the port.

    # ifdown eth2

    # ifup eth2

     

    Determining IP information for eth2... done.

    # ifconfig eth2

    eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

            inet 1.1.6.2 netmask 255.255.255.0  broadcast 1.1.6.255

            inet6 fe80::e61d:2dff:fef2:a45d  prefixlen 64  scopeid 0x20<link>

            ether e4:1d:2d:f2:a4:5d  txqueuelen 1000  (Ethernet)

            RX packets 1  bytes 342 (342.0 B)

            RX errors 0  dropped 0  overruns 0  frame 0

            TX packets 16  bytes 1548 (1.5 KiB)

            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

     

    Verify that the port is enabled with IP address.

     

    3. Optionally, if you have Wireshark open on that port on the server, or on the docker container (see HowTo Enable Wireshark Over Docker Container (MLNX-OS)) you can capture the DHCP packets and analyze them.

     

     

     

    See the attached file for the Wireshark pcap.