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

Hello,

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

gitlabrunnerProfile.network-config.yml file

#cloud-config
version: 2
ethernets:
eth0:
dhcp4: false
dhcp6: false
addresses:
- 10.213.212.100/24 #10.124.126.200/24
gateway4: 10.213.212.1 #10.124.126.1
nameservers:
addresses: [8.8.8.8]

try to configure container profile before its creation

lxc profile set ${LXC_CONTAINER_PROFILE} user.network.config - < ${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.