Changing the default network in LXD

I recently decided to give LXD a try, the newish container solution by Canonical that’s supposed to be better, faster and brighter than anything else.

Being a long time LXC (LinuX Container) user, I felt instantly at home using the LXD command line client, which incidentally is named lxc. But coming from LXC also had one draw back, namely that the default network of was already taken. Not on my local machine, but I do connect to those containers from time to time, so installing LXD cause a little trouble in my routing table, as the default bridge interface, lxcbr0, as well as the DHCP settings are set up automatically during installation with that exact IP range.

But to the point, changing the IP is actually pretty simple if you know where to look. Just open the file /etc/default/lxc-net in your preferred editor and change (all) the IPs according to your requirements.

$ sudo vi /etc/default/lxc-net

Make sure you also change the LXC_DHCP_ parts or otherwise your containers won’t get any IP addresses assigned. Afterwards just restart the lxc-net daemon, and if you want, the lxc daemon as well for good measure.

$ sudo service lxc-net restart
$ sudo service lxc restart

Now your bridge interface should have the correct IP assigned, and after restarting your containers, they should too.

$ ifconfig lxcbr0
lxcbr0 Link encap:Ethernet HWaddr fe:98:ce:aa:5b:6c
inet addr: Bcast: Mask:
inet6 addr: fe80::fc8b:3ff:fe7c:3750/64 Scope:Link
RX packets:130 errors:0 dropped:0 overruns:0 frame:0
TX packets:171 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:25496 (25.4 KB) TX bytes:27297 (27.2 KB)

$ lxc list |grep RUNNING
| dev-caman01 | RUNNING | | | NO | 0 |

That’s it, have fun with LXD.