LXC Container Networking Under Centos 7

Here at Progress Technical, I've decided it's time to trust virtualization with a client's uptime.  It solves a big problem for us.  We have a very old application running in a 32-bit environment and really can't find adequate hosting for such an old app.  Being able to run Centos 6 with PHP 4/5 is a huge gain.  Little did I know there are at least fix very popular virtualization approaches: VMWare, LXC, LXD, Docker, etc.   I am simplifying, so are type 1 virtualization some are type 2.  We settled on LXC for Centos 7 as that's the system more readily available to use and for which we are most familiar.

LXC containers are fairly easy to get going.  There are a lot of good guides for creating a container in that environment.  What is difficult if you haven't been through it is getting a containers to talk on the same network as the host:

Just some notes to self.  My 32 bit container is called mycentos6:

HOST setup:  in /var/lib/lxc/mycentos6/config:

 

# Template used to create this container: /usr/share/lxc/templates/lxc-download
# Parameters passed to the template: -d centos -r 6 -a i386
# For additional config options, please look at lxc.container.conf(5)

# Distribution configuration
lxc.include = /usr/share/lxc/config/centos.common.conf
lxc.arch = x86

# Container specific configuration
lxc.rootfs = /var/lib/lxc/mycentos6/rootfs
lxc.utsname = mycentos6

# Network configuration
lxc.utsname = mycentos6.adelie.loc
lxc.network.type = veth
lxc.network.name = eth0
lxc.network.link = br0
lxc.network.ipv4 = 192.168.0.113/24
lxc.network.hwaddr = 00:1E:2D:F7:E3:4E

CONTAINER ETH0

ifcfg-eth0:
DEVICE=eth0
ONBOOT=yes
HOSTNAME=mycentos6
NM_CONTROLLED=no
TYPE=Ethernet
IPADDR=192.168.0.112
NETMASK=255.255.255.0
GATEWAY=192.168.0.251
DNS1=192.168.0.251
IPV6INIT=no
USERCTL=no

 

One example page that helped:

LXC bridge example CentOS
cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
BOOTPROTO=none
ONBOOT=yes
NM_CONTROLLED=no
BRIDGE=br0
cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
IPADDR=10.66.1.27
NETMASK=255.255.255.0
GATEWAY=10.66.1.1
ONBOOT=yes
BOOTPROTO=none
NM_CONTROLLED=no
DELAY=0
cat /etc/sysconfig/lxc-net
USE_LXC_BRIDGE="false"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.28.14.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.28.14.0/24"
LXC_DHCP_RANGE="10.28.14.2,10.28.14.254"
LXC_DHCP_MAX="253"
cat /var/lib/lxc/test/config
lxc.network.type = veth
lxc.network.flags = up
lxc.rootfs = /var/lib/lxc/test/rootfs
lxc.include = /usr/share/lxc/config/centos.common.conf
lxc.arch = x86_64
lxc.utsname = test.alex.loc
lxc.network.name = eth0
lxc.network.link = br0
lxc.network.veth.pair = veth-01
lxc.network.ipv4 = 10.66.1.61/24
lxc.network.ipv4.gateway = 10.66.1.1
lxc.network.hwaddr = 00:1E:2D:F7:E3:4E 

Previous page: Blog