Introduction

This page describe how to use Vagrant official Debian boxes with LXC to create a private cloud on a Debian machine. For a detailed LXC installation options, please refer to the LXC page.

Architecture

{i} TODO

Host Machine -> Eth0 -> (Bridge interface + nat + DHCP) -> Vagrant LXC Boxes with network access.

Installation

{i} Tested on stretch

Install the following packages

# apt-get install lxc vagrant dnsmasq bridge-utils

Configuration

Networking

Configuring a bridge interface (more details available ont LXC/SimpleBridge): Create lxc-bridge-nat interface to /etc/network/interfaces using eth0 interface.

auto lxc-bridge-nat
iface lxc-bridge-nat inet static
        bridge_ports none
        bridge_fd 0
        bridge_maxwait 0
        address 10.0.0.1
        netmask 255.255.255.0
        # nat from lxc to the World
        up iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
        # nat? dhcp packet from densmaq through lxc-bridge-nat
        up iptables -t mangle -A POSTROUTING -p udp --dport bootpc -j CHECKSUM --checksum-fill

Activate port forwarding for the current session:

echo "1" > /proc/sys/net/ipv4/ip_forward

Permanent port forwarding: adding the following line in /etc/sysctl.conf

net.ipv4.ip_forward = 1

LXC

Configuring LXC to use the lxc-bridge-nat: /etc/lxc/default.conf

lxc.network.type = veth
lxc.network.flags = up
lxc.network.link = lxc-bridge-nat

DHCP

Configuring a minimal dhcp server: /etc/dnsmasq.conf:

interface=lxc-bridge-nat
dhcp-range=10.0.0.100,10.0.0.200,12h

restart dnsmasq service:

service dnsmasq restart

Vagrant LXC

vagrant init debian/jessie64
vagrant up --provider=lxc
vagrant ssh