I came across an issue today where new lxc containers on a machine were failing to get an IP address. In fact it was worse than that, they didn’t appear to have an interface for networking. Just the loopback adaptor.
root@lxc-container:~# ifup eth0 Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Cannot find device "eth0" Bind socket to interface: No such device Failed to bring up eth0.
On the host machine brctl
didn’t show any interfaces on the bridge.
# brctl show bridge name bridge id STP enabled interfaces lxcbr0 8000.56847afe4a99 no
It turns out the answer was in the machines config file. Usually located in /var/lib/lxc/$machine_name/config
.
Normally these contain a section like this defining the network interfaces. In this case it was entirely missing from the configuration file.
lxc.network.type = veth lxc.network.flags = up lxc.network.link = lxcbr0 lxc.network.hwaddr = 00:16:3e:99:99:99
Manually adding those settings to the configuration file setup a working eth0 on the machine when it was restarted.
In this case the reason for the missing section was a dodgy setting in the lxc.default_config
setting that caused the machine setup to choke.
# cat `lxc-config lxc.default_config` lxc.lxcpath = /lxc lxc.network.type = veth lxc.network.link = lxcbr0 lxc.network.flags = up lxc.network.hwaddr = 00:16:3e:xx:xx:xx
In this case we had a rogue parameter, lxc.lxcpath
that shouldn’t have been in the default_config. There wasn’t any visible error running lxc-create however so we didn’t spot it at first. It was only when we added -x
to the shebang line in /usr/share/lxc/templates/lxc-debian
that we saw an error,
root@host-machine:~# lxc-create -n nettest3 -t debian lxc_container: unknown key lxc.lxcpath lxc_container: Failed to parse config: lxc.lxcpath = /lxc …
Once we removed the rogue lxc.lxcpath configuration setting new boxes were created as usual again.