Unable to assign fixed IP to container

Inside /usr/lib/x86_64-linux-gnu/lxc/lxc-net I uncomment:

LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf

I then create /etc/lxc/dnsmasq.conf with the content:

dhcp-host=container,10.0.3.5

I make sure no container are running and restart the lxc-net.service.

lxc-start -n container
lxc-ls --fancy
NAME      STATE   AUTOSTART GROUPS IPV4      IPV6 
container RUNNING 0         -      10.0.3.47 -    

The last block is random each time.

Any ideas?

Check that the process startup time of dnsmasq is indeed after your restart. If that’s the case, then chances are that your container’s dhclient isn’t sending the right hostname somehow.

MAC based assignments tend to be more reliable.

Brainfart! Turns out the --conf-file parameter was not being passed to dnsmasq inside the lxc-net script, because I set the variable in the wrong location! So of course my changes to dnsmasq.conf had no effect.

Setting fixed IPs works fine now by hostname or MAC. :+1:
I also learned that you can use dhcp-host=<host>:ignore if to exempt specific containers, neat!

p.s. Found a typo in the process. That should read LXC_DHCP…