Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Similar to LXC, LXD 2.x can also assign static IP addresses. Almost similar approach but the files are slightly different.

Also note as of LXD 2.3 there are may be networking tools that take care of this. Modify /etc/default/lxd-bridge to reference an external dnsmasq.conf,Not looking into 2.3 details yet as Ubuntu Server 16.04.2 LTS is packaged with 2.0.9.

You may also set some of the range setting when the network is being setup on running of the lxd init command.

Also, change the default DHCP range,

Code Block
languagebash
sudo# cpNOTE sudoyou sed -i 's/LXD_CONFILE=""/LXD_CONFILE=""' /etc/default/lxd-bridge

Also, change the default DHCP range,

Code Block
languagebash
can't use these commands as is... because "lxd init" randomly picks the ip subnet.
# When time permits can create scripts on top to compensate.
sudo sed -i 's/LXD_IPV4_DHCP_RANGE="10.232.27.2,10.232.27.254"/LXD_IPV4_DHCP_RANGE="10.232.27.100,10.232.27.254"' /etc/default/lxd-bridge
sudo sed -i 's/LXD_IPV4_DHCP_MAX="252"/LXD_IPV4_DHCP_MAX="154"' /etc/default/lxd-bridge

This will make available 10.232.27.3 to 10.232.99.

Create a dnsmasq.conf file where you may reserve IP Addresses based on server names,

... refer to the LXC instructions until incorporated here...

Modify /etc/default/lxd-bridge to reference an external dnsmasq.conf file,

Code Block
languagebash
sudo cp /etc/default/lxd-bridge /etc/default/lxd-bridge.ori
# This line does not work yet, I need lookup how to escape the /.
# EDIT: should work now - samir
sudo sed -i 's/LXD_CONFILE=""/LXD_CONFILE="\/opt\/lxd\/dnsmasq.conf"/' /etc/default/lxd-bridge

Restart the services to make sure things went well,

Code Block
languagebash
sudo service lxd-bridge stop
sudo service lxd-bridge start


Reference

http://jason.trickett.us/2016/08/lxd-containers-static-ip-addresses-heres/ - Source article for this but missing some details on changing the default range otherwise you'll end up with collisions.