Exporting container & importing as another container name (to test the export file) results in: Error: Failed start validation for device "eth0": MAC address

I have a container, container-name, with a static IP.

With that container stopped, backed it up via:

lxc export container-name ./container-name.tar.gz --optimized-storage

Then imported that export file, in order to test the backup, via:

lxc import ./container-name.tar.gz container-name-test

Then, with container-name still stopped, tried starting container-name-test via:

lxc start container-name-test

And with that I receive the following error:

Error: Failed start validation for device “eth0”: MAC address “00:16:3e:e7:0a:45” already defined on another NIC
Try lxc info --show-log container-name-test for more info

There is no info in the log section of:

lxc info --show-log container-name-test

So, ultimately, I just want to be able to import the exported container-name as container-name-test so that I can verify the backup is good & works fine for re-importing it.

What do I need to do in order to accomplish this?

I figured out another way of doing what I was trying to accomplish with the above with the goal of verifying my backup.

These are the steps I took:

  1. Copy container-name to container-name-backup
  2. Change the static IP of container-name-backup to something different than what container-name uses.
  3. Then close, export & delete container-name-backup container.
  4. With that I was able to import the container-name-backup.tar.gz file and start that container right up for testing.

The problem here is that when importing the containing from the backup, it comes with a virtual NIC card with the same MAC address as the original isntance because it is preserved on the backup.
For example, copies can also suffer from this if the container has a NIC device with hwaddr set, in which case the copy would inherit the MAC address on the NIC card. This can be achieved by running:

lxc config device override c1 eth0 hwaddr=00:16:3e:eb:66:cd
lxc copy c1 c2
lxc start c2

Thus, to fix your problem you can just use lxc config device override container-name eth0 hwaddr=something to change the MAC address of one of the containers to something different than you see on the error and that way avoid the collision.
If you don’t want to mess with the device config, you can also try importing the container back into a different project.

You can avoid getting the conflict at import time by using the --device flag to change the imported instance’s MAC address, e.g.:

lxc import ./container-name.tar.gz container-name-test \
    --device eth0,00:16:3e:e7:0a:46