Setting a static IP address using network bridge

If you don’t need the containers that are connected to the external network to be able to communicate with the LXD host (and vice versa) then you can just use a macvlan NIC type, specifying the external interface as the parent. This way you won’t need any unmanaged bridges at all.

lxc config device add <instance> eth0 nic nictype=macvlan parent=<external interface>

Then inside the container, configure its static IP as you would with a normal system.

See https://linuxcontainers.org/lxd/docs/master/instances#nic-macvlan

If you need to the containers to be able to communicate with the host then you will be limited to using either bridged or routed NIC types. The former requires setting up an unmanaged bridge and connecting it to the external interface (see https://netplan.io/examples/#configuring-network-bridges) and then using a bridged NIC type with the parent set to the bridge interface, e.g.:

lxc config device add <instance> eth0 nic nictype=bridged parent=<external interface>

Then inside the container, configure its static IP as you would with a normal system.

See https://linuxcontainers.org/lxd/docs/master/instances#nic-bridged

Keep in mind that for both macvlan and bridged NIC types, the instances will get their own MAC address on the external network (as if they are physically connected to it), and in some production environments (and sometimes when running inside another hypervisor) the number of different MAC addresses per physical port is limited to one.

To get around this we have the routed NIC type which shares the MAC address of the host’s external interface and doesn’t require a separate unmanaged bridge be setup.

The routed NIC type can also be useful in environments where the upstream network doesn’t provide a dedicated subnet of IPs to use, and instead routes non-sequential IPs to your LXD host.

To add a routed NIC type use:

lxc config device add <instance> eth0 nic nictype=routed parent=<external interface> ipv{n}.address=<static ip>

Then inside the container, you need to ensure that either A) the container’s network setup doesn’t remove the static IP and routing added to the NIC by LXD or B) set up the network config to it mirrors the setup added by LXD.

See https://linuxcontainers.org/lxd/docs/master/instances#nic-routed

See How to get LXD containers get IP from the LAN with routed network