Reset volatile.eth0.hwaddr to automatic mac

Hello,

per default lxd generates his own mac address for the interface. Sometimes i must set static mac adresses for the interface, but sometimes i must revoke to default. Is there a way to unset the key volatile.eth0.hwaddr of my container ? I have tried to use
lxc config set mycontainer volatile.eth0.hwaddr -
lxc config set mycontainer volatile.eth0.hwaddr 0
lxc config set mycontainer volatile.eth0.hwaddr

but nothing works.

Try:

lxc config unset mycontainer volatile.eth0.hwaddr
1 Like

Hi tomp,

sorry this does not work. The static mac will be still present, stop and start take no effect to.

If you have specified a static MAC address, you can remove that with:

lxc config device unset mycontainer eth0 hwaddr

Hi tomp,

thank you for your help, i have tested this too. But it does not work i got
Error: The device doesnā€™t exist

Please note i have set the mac with
lxc config set volatile.eth0.hwaddr MAC

Perhaps your device is part of the profile and not unique to the container.

Please can you show me the output of:

lxc config show mycontainer

and

lxc profile show default

Here are the output:

lxc config show srv1000
architecture: x86_64
config:
boot.autostart: ā€œfalseā€
image.architecture: x86_64
image.description: Busybox x86_64
image.name: busybox-x86_64
image.os: Busybox
limits.cpu: ā€œ2ā€
limits.memory: 2048MB
limits.processes: ā€œ1000ā€
volatile.base_image: 74186c79ca2f22c1a566ebaf99f67f52313814429d110b16677b7d74b9e6e26b
volatile.eth0.host_name: veth1D573Z
volatile.eth0.hwaddr: 82:88:30:30:56:d4
volatile.idmap.base: ā€œ0ā€
volatile.idmap.current: ā€˜[{ā€œIsuidā€:true,ā€œIsgidā€:false,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000},{ā€œIsuidā€:false,ā€œIsgidā€:true,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000}]ā€™
volatile.idmap.next: ā€˜[{ā€œIsuidā€:true,ā€œIsgidā€:false,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000},{ā€œIsuidā€:false,ā€œIsgidā€:true,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000}]ā€™
volatile.last_state.idmap: ā€˜[{ā€œIsuidā€:true,ā€œIsgidā€:false,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000},{ā€œIsuidā€:false,ā€œIsgidā€:true,ā€œHostidā€:1000000,ā€œNsidā€:0,ā€œMaprangeā€:1000000000}]ā€™
volatile.last_state.power: RUNNING
devices: {}
ephemeral: false
profiles:

  • default
    stateful: false
    description: ā€œā€

#####################
lxc profile show default
config: {}
description: Default LXD profile
devices:
eth0:
name: eth0
nictype: bridged
parent: routebr
type: nic
root:
path: /
pool: default
type: disk
name: default
used_by:

  • /1.0/containers/srv1000

Thanks, as I thought, your container doesnā€™t yet have an eth0 device that is configurable individually, as its inherited from the profile.

Setting the volatile key directly is an approach, although really those volatile keys are meant for internal usage and so their purpose can vary over time, so I would not recommend it.

Instead try overriding the profileā€™s etho device on your specific container as follows:

lxc config device add mycontainer eth0 nic nictype=bridged parent=routebr hwaddr=my:static:mac:address

Then if you need to change it in the future you then should be able to do:

lxc config device set mycontainer eth0 hwaddr a:new:mac:address

And if you want to revert to automatic volatile generation of MAC address you can then do:

lxc config device unset mycontainer eth0 hwaddr

Hi tomp,

i tink the best way is to start my container without any interface and then i add the interface with your suggestion thanks for help.

[Same question, different user/year]: WHY did I not think of that an hour ago. THANK YOU.