Recently discovered this issue myself⊠Its because the export backs up the hardware address (mac address) of the container.
Since DHCP keys IP address from the hardware address they will both be assigned the same IP.
The fix is to unset the hardware address on clones of your import and then lxd will automaticly assign it a new hardware address.
If your like myself and rely on the default profile for the lxdbr0 entry⊠You will have to unset âvolatile.eth0.hwaddrâ which works but is bad practice as all the volatile config is internal and subject to change without notice.
So on my system I import the container⊠if its running I stop itâŠ
then I run
Also, if youâre looking to create multiple instances from a backup, then you could also consider using lxc publish to publish the instance as an image instead of lxc export. This would mean that each instance created from that image (using lxc init <image name>) will get its own fresh config (including MAC address).
When using lxc export you are creating a backup of a single instance, and the intended use-case for that is to restore a single instance (because it is a backup).
When restoring the backup all of the original config is restored, including the MAC address.
A DHCP server generates IP assignments based on the MAC address, so if the MAC address is the same then the same IP will be allocated. However even aside from that issue, if you have two active instances with the same MAC address you are going to see other network issues.
Also if we started altering MAC address config on backup restoration this would cause issues for people who have used static IP allocation or network security rules based on MAC address.
If youâre looking to create multiple instances from a source instance, then you need to change the MAC address as @Ozymandias described, or use the lxc publish mechanism to create an image that can be used as the basis of multiple instances (which LXD then treats differently from restoring a backup by removing any volatile config, such as MAC address, so that each instance generates its own MAC address, and thus own IP allocation in DHCP).
I am ok with the current behaviour and made necessary changes in my system for backup and restore.
Still the command syntax of lxc import implies that a new container is created from the backup. If itâs lxc restore it will than be correct to assume that container will be the same including name. If the old container exist lxc restore will fail (this will indicate to sys admin to either rename the old container or delete it, before restoring the backup). This will mean the container name should automatically come from backup.
In my view this will help avoid having same Mac or IP address which will result in difficult to diagnose errors.
How about extending it to define the backup file as another option?
I havenât used lxc restore to restore from snapshots. I always launched a new container from snapshot and then just point the load-balancer towards new container. This makes it easier to have immutable container based infrastructure, in case the new container has an issue can point load-balancer to old container.
I just ran into this issue as well, and had to Google this thread to see what was going on. I didnât even realize that the machines had duplicate IP addresses until after running the import operation multiple times.
If the âintended use caseâ is to restore to the same VM, then why is there an option that allows you to specify a new VM name? Shouldnât the user have some kind of warning that thereâs conflicting MAC addresses on the same network?
Itâs obvious to an experienced user whatâs happening, but itâs not necessarily at top of mind until you realize the effects later on. Beginner users, who donât have networking experience, would be utterly confused at this.
I agree this is confusing, please can you log a github issue.
LXD does already have duplicate MAC detection (which is the root cause of this issue, 2 NICs with the same MAC).
For example:
lxc launch ubuntu:jammy c1
lxc ls
+------+---------+--------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+------+---------+--------------------+-----------------------------------------------+-----------+-----------+
| c1 | RUNNING | 10.21.203.8 (eth0) | fd42:ffdb:caff:baf7:216:3eff:fee2:d8fb (eth0) | CONTAINER | 0 |
+------+---------+--------------------+-----------------------------------------------+-----------+-----------+
lxc config get c1 volatile.eth0.hwaddr
00:16:3e:e2:d8:fb
lxc init ubuntu:jammy c2
lxc config set c2 volatile.eth0.hwaddr=00:16:3e:e2:d8:fb
lxc config get c2 volatile.eth0.hwaddr
00:16:3e:e2:d8:fb
lxc start c2
Error: Failed start validation for device "eth0": MAC address "00:16:3e:e2:d8:fb" already defined on another NIC
So I would expect lxc import to succeed and then the start of the instance fail with that sort of error, allowing you to fix the issue with lxc config edit.
Agreed, the import operation should succeed. There should also be an immediate warning displayed to the user, indicating that a MAC address (and/or other internal LXD unique identifiers) conflict has been detected. The warning should recommend corrective action.