How to make IPs fixed to an instance from the managed bridge?

When using lxc restore instance backup-snapshot the instance got new IPs from lxdbr0. I’d like a general setting for LXD/lxdbr0 to remember and keep the IP addresses that were given on instance creation.

I know about setting the IP statically inside the instance and with other devices, and so on, is possible, but I’d like an easy way to do this kind of thing, the name of an instance does not change after restoring a snapshot, so why should other unique identifiers like IPs?

You should create a static DHCP allocation using:

lxc config device override <instance> eth0 ipv4.address=n.n.n.n

Then when you create a snapshot that static allocation config will be stored inside it and used when restoring.

1 Like

Hi @tomp , thanks again! You’re the best!

I also found out that the lease is made using the hardware macaddress, fortunately I had it in the bash history so I manually added the network device with the “old” hardware address and the old IPs came back.

Do you think it would make sense to be able to bake this kind of thing into the instance creation?
Like a flag --fixed-ips or anything in that direction to do that kind of overriding the profile and fixing it to the instance? Hardcoding it into the instance right at creation time.

And quick question: Will the ip stick even when moving the instance to another host?

1 Like

If you’re using the API to create the instance you can populate the Devices field with the IP reservations you want at create time.

The lxc init and lxc launch commands don’t currently have a --device flag like lxc copy and lxc move commands have, which allows overriding specific config for a specific device.

@stgraber do you foresee any issues with adding a --device flag to lxc init and lxc launch?

1 Like

The syntax is going to be a bit weird because we need a name + a bunch of key/value.
But there is some precedent for that with lxc copy.

Currently your alternative is to feed a YAML input to lxc launch that includes the configuration you’d like.

1 Like

Yeah it currently uses -d <device>,<key>=<value>


1 Like