Adding Static Leases to LXC in Ubuntu Trusty Tahr 14.04.2 LTS
March 29, 2015
Posted by on
If you want to have more control over DHCP in the default LXC installation in Ubuntu Trusty Tahr then you can edit the file /etc/default/lxc-net to suit you.
It is recommended that you uncomment the line:
…because the /etc/lxc/dnsmasq.conf file is where you will add static lease configuration information later.
Note that you do not need to make any changes to /etc/init/lxc-net.conf as the settings in /etc/default/lxc-net will take preference.
Next you will want to find the MAC addresses of your LXC containers:
# grep lxc.network.hwaddr /var/lib/lxc/*/config
/var/lib/lxc/lxctutorial/config:lxc.network.hwaddr = 00:16:3e:32:9a:a4
/var/lib/lxc/webserver/config:lxc.network.hwaddr = 00:16:3e:0c:5b:1b
/var/lib/lxc/mailserver/config:lxc.network.hwaddr = 00:16:3e:ca:cb:02
Then assign them the static addresses you want them to have in /etc/lxc/dnsmasq.conf e.g.:
# static leases
Now you need two steps to make sure this takes effect:
echo "" >/var/lib/misc/dnsmasq.lxcbr0.leases # erase current leases