LXC Configuration

Configuration Locations

LXC knows the following configurations locations:

  • System: /etc/lxc/*
  • Local: /srv/lxc/containers/*/config

Other locations:

  • Preseed and configuration scripts: /etc/lxc/debconfig which is maintained on git.its.bfh.ch
  • Auto start links: /etc/lxc/auto
  • Internal preseed package: /usr/share/lxc/packages
  • Internal lxc template scripts: /usr/share/lxc/templates

Host Network

Enable IP Forward

echo "net.ipv4.ip_forward = 1" > /etc/sysctl.d/ip_foward.conf
sysctl -p

Bridge Interfaces (dhcp standalone)

# /etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet manual

auto br0
iface br0 inet dhcp
     bridge_ports    eth0

     bridge_fd       0
     bridge_hello    0
     bridge_maxwait  0
     bridge_stp      0

Bridge Interfaces (static standalone)

# /etc/network/interfaces

auto lo
iface lo inet loopback

iface eth0 inet manual

# standalone: 192.168.0.2
auto br0
iface br0 inet static
     address         192.168.0.2
     broadcast       192.168.0.255
     gateway         192.168.0.1
     netmask         255.255.255.0
     network         192.168.0.0

     pre-up          ifconfig eth0 down
     pre-up          ifconfig eth0 up

     bridge_ports    eth0

     bridge_fd       0
     bridge_hello    0
     bridge_maxwait  0
     bridge_stp      0

Bridge Interface (static subnet)

#/etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual

# subnet: 192.168.0.1/24
auto br0
iface br0 inet static
     address         192.168.0.1
     broadcast       192.168.0.255
     netmask         255.255.255.0
     network         192.168.0.0

     pre-up          brctl addbr br0
     post-down       brctl delbr br0

     bridge_fd       0
     bridge_hello    0
     bridge_maxwait  0
     bridge_stp      0

Container Network

Physical Network

lxc.network.type = phys
lxc.network.flags = up
lxc.network.hwaddr = 00:FF:00:00:00:03
lxc.network.link = eth1
lxc.network.name = eth0
lxc.network.ipv4 = 192.168.0.3/24
lxc.network.ipv4.gateway = 192.168.0.1