I'm playing around with LXC on my Arch Linux workstation as a learning experience. I'm following the guide on the LXC page on the Archwiki and setting up a static ip for the container. This is what my network config is like:

Description="LXC Bridge"

And the container config:

lxc.network.type = veth
lxc.network.link = br0
lxc.network.ipv4 =

However according to lxc-ls -f it gets given an extra ip address.

NAME          STATE   AUTOSTART GROUPS IPV4                         IPV6
testcontainer RUNNING 0         -, -

I only want I'm not sure why it's getting the second one assigned to it.


So after a little bit more research I've determined why this is happening. I'm using the default Ubuntu and Debian templates to create the containers and their networking is set up so as to use DHCP to ask for a IP from the the router. So initially the static IP is set using the lxc.container.config and then when the container starts it queries the router (or whatever DHCP server you have) for a secondary IP that's then assigned to it.

The most logical way to stop this is likely to just assign the static ip inside the container. So on Debian based templates edit /etc/network/interfaces:

auto etho0
iface etho0 inet static

And then remove the ipv4 line from the lxc config /var/lib/lxc/testcontainer/config:

lxc.network.type = veth
lxc.network.link = br0

Another method is to let the host set the ip by keeping the ipv4 line in /var/lib/lxc/testcontainer/config and to tell the container explicitly to not touch the interface by setting it to manual:

auto eth0
iface eth0 inet manual

Apparently there are some issues with this second method if the host is suspended and then resumed. Probably best to use the first method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.