How can i set static ip address for my lxc container (lxcbr0)?


During last days, I try to setting my container to specified static ip address but no way . How can i do that ? file

version: 2
dhcp4: false
dhcp6: false
- #
gateway4: #
addresses: []

try to configure container profile before its creation

lxc profile set ${LXC_CONTAINER_PROFILE} - < ${LXC_CONTAINER_PROFILE}.network-config.yml

lxc profile set ${LXC_CONTAINER_PROFILE} user.user-data - < ${LXC_CONTAINER_PROFILE}.yml

Is lxcbr0 a LXD managed bridge? Are you running a DHCP server on that interface?

If so you could setup a static DHCP lease for the server’s MAC address so its always given the same IP.

If not then take a look at How to get LXD containers get IP from the LAN with routed network as although its for the routed NIC type, it has some good examples on using cloud-init for configuring static IPs inside the container.