2

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:

/etc/netctl/lxcbridge
---------------------
Description="LXC Bridge"
Interface=br0
Connection=bridge
BindsToInterfaces=(enp1s0)
IP=static
Address=('192.168.0.20/24')
Gateway='192.168.0.1'
DNS=('192.168.0.1')

And the container config:

/var/lib/lxc/testcontainer/config
---------------------------------
lxc.network.type = veth
lxc.network.link = br0
lxc.network.ipv4 = 192.168.0.198/24

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

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

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

1

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
    address 192.168.0.15
    netmask 255.255.255.0
    gateway 192.168.0.1

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.