Was continuing to work on this and then tried this:
stopped each container (original and its copy (with now a different name)) then started both at once.
Operation a success! Each container has a different IPv4 address!!!
I had remembered that it was something simple but I haven’t been able to find any references to this technique.
So for hopefully someone else’s use - - - there it is!
When a container starts up, it will ask for a new IP address from the LXD DHCP server.
Each container should have a unique MAC address, which is randomly selected.
The LXD DHCP server can distinguish between containers if they have different MAC addresses.
The chances for a collision (two containers that happen to get the same random MAC address) is around 1 in 10 trillion. Therefore, if you manage to get two containers with the same IP (because same MAC address), ask again here because it would be an interesting bug. Use a title like BUG: MAC Address collision in two containers.
Thank you for your technical response - - - useful clarification.
What was (and is) fascinating to me was that when I started the cloned container for the first time the two ipv4 addresses were the same. The ipv6 addresses were not, but they differed in only the last 2 quads.
I had not done an ifconfig on the originating container throughout the attempts to change the ipv4 address so I did one now - - and they do share the first 3 pairs but not the next 3 (as you suggested) of the MAC address.
What was (and is) confusing to me is why the dhcp server ‘did’ give the same ivp4 address.
I was able to affect the needed change so situation is good but am still confused as to why an automated tool would generate the same ivp4 address from 2 different MAC addresses.
Here it shows you what DNSMASQ (the one for LXD) thinks about the MAC Address of the containers.
In /var/snap/lxd/common/lxd/logs/ you can find the LXD logs, and also individual logs per container.
A real physical network interface has a proper, unique and defined MAC address. On the contrary, a virtual network interface (like those in containers) has a 00:16:3e:??:??:?? MAC address that is randomly generated when the container image is instantiated. It keeps the first part (00:16:3e) so that it is distinguishable from other interfaces.
For your case, if you want to delve deeper, you can have a look at the logs.
Interesting and fascinating - - - sorry - - - I’m thinking I can actually understand this yet at the same time I don’t understand.
There are 6 MAC addresses defined in /var/snap/lxd/common/lxd/networks/lxdbr0 yet I have 5 containers. Is the sixth one for lxdbr0 itself?
Spent a little time looking at files like your 2 examples and I get 5 MAC addresses and the ipv4 address that is linked with lxdbr0.
Thank you - - - interesting stuff!
Sorry for resurrecting a very old thread, but I just ended up with two containers having the same MAC addresses using a similar example, but with snapshots:
lxc launch ubuntu:x c1
lxc snapshot c1 test
lxc cp c1 c2
lxc restore c2 test
lxc start c2
Both containers c1 and c2 now have identical MAC addresses and identical /etc/hostname (c1). Is there a way to force generation of a fresh MAC addresses and fixing the hostname? The only workaround I found is to copy c2 again:
Thanks, that worked! However, not much shorter than copying / renaming the container.
Does it mean that the volitile values like MAC address are saved in snapshot and are overwritten when restoring from snapshots?