[lxc-users] LXD assigning static IP's at start tp containers

Mark Constable markc at renta.net
Sat May 16 07:30:33 UTC 2015


On Fri, 15 May 2015 10:54:08 PM Kevin LaTona wrote:
> I was reading about ways in legacy LXC of being able to have the DHCP server
> assign static IP's to containers at startup based upon container name.
> If one is using Ubuntu 15.04, systemd and LXD is that still possible?

Hey Kevin, I just set something like this up and although this may not
be "the right way" to do it works for my situation which sounds somewhat
similar to what you are after. Best I should show my relevant config
files and some of this may help you or provide some ideas...

My main gateway/wireless/dhcp router is 192.168.0.1

~ grep -Ev "^(#|$)" /etc/default/lxc-net
USE_LXC_BRIDGE="true"
LXC_BRIDGE="lxcbr0"
LXC_ADDR="192.168.0.2"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="192.168.0.0/24"
LXC_DHCP_RANGE="192.168.0.2,192.168.0.54"
LXC_DHCP_MAX="53"
LXC_DHCP_CONFILE=/etc/lxc/dnsmasq.conf
LXC_DOMAIN="example.org"

And the magic to fill in the gaps above...

~ cat /etc/rc.local
sleep 5 && {
 brctl addif lxcbr0 eth0
 sleep 1
 route add default gw 192.168.0.1
 echo "nameserver 8.8.8.8" > /etc/resolv.conf
}
exit 0

~ cat /etc/lxc/dnsmasq.conf
dhcp-host=sysadm,192.168.0.3
dhcp-host=markc,192.168.0.4


I also remove ifupdown and resolvconf and set all my NetworkManager
interfaces not to "autoconnect=false" so if I need to switch to wifi
when moving my laptop away from an eth cable I can ifconfig down lxcbr0
select a wifi connection.



More information about the lxc-users mailing list