When you create some containers on a host, e.g.:

sudo lxc-create -n container1 -t ubuntu
sudo lxc-create -n container2 -t ubuntu

the LXC system creates IP address for the hosts on a new subnet, e.g.

lxc-ls --fancy
NAME            STATE    IPV4        IPV6  AUTOSTART
container1  RUNNING  -     NO
container2  RUNNING   -     NO

The question is, where is the DHCP service which is allocating these addresses, and how can we allocated a fixed IP based on the server name or MAC address?

We tried editing /etc/lxc/default.conf and adding:


Then stopping and starting the containers and doing sudo service lxc-net restart but this had no effect. I could edit /etc/network/interfaces on each container and hard code an IP instead of using DHCP, but I would rather control it centrally.

Is there a way to do this?


OK, found another way to do it which works:

  1. Stop all containers
  2. Edit /etc/default/lxc-net
  3. uncomment "LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf"
  4. create the file /etc/lxc/dnsmasq.conf
  5. edit dnsmasq.conf:


  6. service lxc-net restart

Now restart the containers and bask in the glory of your own IPs.

-- EDIT --

Spoke too soon - this only half works.

There are 4 containers, and in the dnsmasq.conf I have:


Now when I restart evertying, including the containers, I get this:

# lxc-ls --fancy
host01    RUNNING   -     YES
host02    RUNNING   -     YES
host03    RUNNING  -     YES
host04    RUNNING   -     YES

It got half of them right. All containers we created in the same way, and have not been edited in any way.

Anyone has any ideas whats going on?

This is the contents of the /etc/network/interfaces on one of the offending containers:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

Nothing different to the working ones.

-- EDIT 2 ---

stopping all the containers, then running this:

$ sudo restart lxc-net

Fixed the issue!

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.