Howto add hwaddr to nic created with profile?

Is there a way to add hwaddr to nic created with profile?
for example I got profile macvlan:
devices:
eth0:
nictype: macvlan
parent: enp0s31f6
type: nic

and i cant setup hwaddr for eth0

lxc config device set container eth0 hwaddr 00:50:56:01:32:22
Error: The device doesn’t exist

regards

You can do:

lxc config device override <instance> <device> hwaddr 00:50:56:01:32:22

The override command copies the NIC config from the profile into the instance and then modifies the config key(s) you provide.

wow it works! thx
but
is it normal that now
volatile.eth0.hwaddr is missing from container config
when i set up
eth hwaddr option?

regards

Yes that is normal, what’s happened there is in overriding the profile device, it will have removed the profile device from the instance (clearing any associated volatile keys) and then added a new instance device (with the profile config plus the overridden hwaddr) to the instance which then doesn’t create a volatile key.

thx for clarification
I assume that volatile.eth0.hwaddr automatically will be back when i remove hwaddr from nic eth0?

regards

Yep thats right.

nice thx

Is there a way to set hwaddr before the instance is launched?

If the device is added through a profile, you can try using -d flag:

incus launch images:ubuntu/jammy/cloud -p default -p <profile_name> <container_name> -d eth0,hwaddr="00:50:56:01:32:22"

Where eth0 is my nic device and 00:50:56:01:32:22 is a new MAC address. You can switch incus to lxc of course.

Command incus launch --help explains the -d flag as:

-d, --device                New key/value to apply to a specific device
1 Like