Ethernet Research

Actionable information about cloud technologies

Linux Containers - Advanced LXC Networking - Part 01

In the previous article I discussed about some basic LXC networking concepts. In this article I’ll discuss about the LXC configuration files that play a key role in automated provisioning of the interfaces and bridges.

Who Tells LXC to Create lxcbr0 ?

The answer is: /var/lib/lxc/test-container/config.  The file has several sections and the networking section at the bottom of the file is what we are interested in.

$ sudo cat /var/lib/lxc/test-container/config
# Template used to create this container: /usr/share/lxc/templates/lxc-ubuntu
# Parameters passed to the template:
# For additional config options, please look at lxc.container.conf(5)

# Common configuration
lxc.include = /usr/share/lxc/config/ubuntu.common.conf

# Container specific configuration
lxc.rootfs = /var/lib/lxc/test-container/rootfs
lxc.mount = /var/lib/lxc/test-container/fstab
lxc.utsname = test-container
lxc.arch = amd64

# Network configuration = veth = up = lxcbr0 = 00:16:3e:b4:86:23

This is a container specific configuration file. There is a global or default configuration file at “*/etc/lxc/default.conf” *used by a container in the absence of a container specific configuration file.

$ cat /etc/lxc/default.conf = veth = lxcbr0 = up = 00:16:3e:xx:xx:xx

Who configures the IP address for the lxcbr0 ? Who specifies the DHCP range for the containers connected to lxcbr0 ? For this we need to look at file: /etc/init/lxc-net.conf

$ cat /etc/init/lxc-net.conf
description "lxc network"
author "Serge Hallyn <>"

start on starting lxc
stop on stopped lxc

env USE_LXC_BRIDGE="true"
env LXC_BRIDGE="lxcbr0"
env LXC_ADDR=""
env LXC_DHCP_MAX="253"
env varrun="/run/lxc"

In addition to the lxcbr0 settings, the above file also programs the iptables with NAT rules(masquerade)such that the container can talk to the outside world or internet.

$ sudo iptables --list -t nat
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

target     prot opt source               destination         
MASQUERADE  all  --         !         

Interface Configuration Files:

The interface specific configurations are stored in /etc/network/interface. You can edit this file to make changes to the interface configuration. In the example below, eth0 is configured to use DHCP to talk to *lxcbr0, *acting as DHCP server, to get its IP address. However, if you want to assign a static IP address to the test-container, you may edit the file to do so. Changes to this file are carried across container reboot.

root@test-container:/# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

To configure static IP address on eth0 change the eth0 configuration in the file to some like this:

auto eth0
iface eth0 inet static