How to ensure public IPs will remain static in lxd container?

I have configured one container with following details on the network
ubuntu@machine3:~$ lxc profile show default2
config: {}
description: Default LXD profile
name: eth0
nictype: macvlan
parent: enp0s8
type: nic
path: /
pool: default
type: disk
name: default2

  • /1.0/containers/container1-default2

On starting the container I got one public IP.
lxc list output
| container1-default2 | RUNNING | (eth0)

How can I ensure that this IP will remain stick with this container even if this container is down for some days … basically I need to ensure that IP remains with this container … is there any file where this can be ensured or ways to confirm above doubt?


Since it is macvlan, it is outside of the reach of lxd. You can either configure your DHCP server to always set this IP for your container’s MAC address. Or setup them up manually.

Thanks @simos for your suggestion …
You mentioned setup manually … I am assuming you mean under /etc/netplan/ … and do I also need to attach the network in the config file of the container with ipv4.address = IP?

No need to attach the network to the container as it has no effect for macvlan.