Hi,
(tl;dr : how can I clone a KVM-based bridged virtual machine and force a duplicate MAC address ?)
Up until recently I've been using VirtualBox on my workstation to test various local setups. Usually I would setup a basic CentOS installation, and whenever I wanted to fiddle around, I would just clone that system and play around with it. So whenever I shot myself in the foot on that VM, I would simply erase it and start over again with a new clone. Think of it as a disposable VM.
All my VMs under VirtualBox used bridged mode, so they were in the same network. And in my local proxy server, I have Dnsmasq that assigns static IP addresses and meaningful hostnames to these VMs. Here's what the corresponding lines in dnsmasq.conf look like:
dhcp-host=08:00:27:00:00:01,suse-lp151,192.168.2.10 dhcp-host=08:00:27:00:00:02,suse-lp152,192.168.2.11 dhcp-host=08:00:27:00:00:03,ce7-server,192.168.2.12 dhcp-host=08:00:27:00:00:04,ce8-server,192.168.2.13 dhcp-host=08:00:27:00:00:05,ol7-server,192.168.2.14 dhcp-host=08:00:27:00:00:06,ol8-server,192.168.2.15 dhcp-host=08:00:27:00:00:07,rh7-server,192.168.2.16 dhcp-host=08:00:27:00:00:08,rh8-server,192.168.2.17
Over the last two weeks, I decided to migrate from VirtualBox to KVM even for local configurations and virtualized desktop configurations. So far, everything works nice... except one problem I can't seem to solve (yet).
I'm using KVM in bridged mode, over a br0 bridge on my workstation. Like with VirtualBox, all my KVM virtual machines are part of my local 192.168.2.0/24 network.
Unfortunately there is no way to simply make a perfect clone of a virtual machine using virt-manager. It insists on assigning my cloned VM a different MAC address. And whenever I want to manually create a NIC with the same MAC address as the original, Virtual Machine Manager tells me I can't do that. Same player shoot again.
Now I know that is normally a good thing. You don't want MAC address conflicts in your network. But here's the thing: I don't intend to fire up both copies at once. As with VirtualBox, I only intend to use one VM at a time, for testing purposes. Now how can I "explain" this to Virtual Machine Manager without having to jump through burning loops ?
Cheers,
Niki
On 25/03/21 5:51 am, Nicolas Kovacs wrote:
Hi,
(tl;dr : how can I clone a KVM-based bridged virtual machine and force a duplicate MAC address ?)
Up until recently I've been using VirtualBox on my workstation to test various local setups. Usually I would setup a basic CentOS installation, and whenever I wanted to fiddle around, I would just clone that system and play around with it. So whenever I shot myself in the foot on that VM, I would simply erase it and start over again with a new clone. Think of it as a disposable VM.
All my VMs under VirtualBox used bridged mode, so they were in the same network. And in my local proxy server, I have Dnsmasq that assigns static IP addresses and meaningful hostnames to these VMs. Here's what the corresponding lines in dnsmasq.conf look like:
dhcp-host=08:00:27:00:00:01,suse-lp151,192.168.2.10 dhcp-host=08:00:27:00:00:02,suse-lp152,192.168.2.11 dhcp-host=08:00:27:00:00:03,ce7-server,192.168.2.12 dhcp-host=08:00:27:00:00:04,ce8-server,192.168.2.13 dhcp-host=08:00:27:00:00:05,ol7-server,192.168.2.14 dhcp-host=08:00:27:00:00:06,ol8-server,192.168.2.15 dhcp-host=08:00:27:00:00:07,rh7-server,192.168.2.16 dhcp-host=08:00:27:00:00:08,rh8-server,192.168.2.17
this appears to have 8 different mac addresses and then assigned 8 individual IP addresses - that would appear desireable and correct.
Why do you want the same mac? what are you trying to achieve?
Feel like I'm missing something
Over the last two weeks, I decided to migrate from VirtualBox to KVM even for local configurations and virtualized desktop configurations. So far, everything works nice... except one problem I can't seem to solve (yet).
I'm using KVM in bridged mode, over a br0 bridge on my workstation. Like with VirtualBox, all my KVM virtual machines are part of my local 192.168.2.0/24 network.
Unfortunately there is no way to simply make a perfect clone of a virtual machine using virt-manager. It insists on assigning my cloned VM a different MAC address. And whenever I want to manually create a NIC with the same MAC address as the original, Virtual Machine Manager tells me I can't do that. Same player shoot again.
Now I know that is normally a good thing. You don't want MAC address conflicts in your network. But here's the thing: I don't intend to fire up both copies at once. As with VirtualBox, I only intend to use one VM at a time, for testing purposes. Now how can I "explain" this to Virtual Machine Manager without having to jump through burning loops ?
Cheers,
Niki
On Wed, 2021-03-24 at 17:51 +0100, Nicolas Kovacs wrote:
(tl;dr : how can I clone a KVM-based bridged virtual machine and force a duplicate MAC address ?)
Both virt-manager and virt-clone prevent you from doing this. However, you can change the created random MAC using virsh edit on the cloned domain.
Terveisin, <(*) Jyrki Tikka
Le 26/03/2021 à 03:09, Jyrki Tikka a écrit :
Both virt-manager and virt-clone prevent you from doing this. However, you can change the created random MAC using virsh edit on the cloned domain.
Do you mean that I can use virsh edit to define an identical MAC address for the original VM and the clone?
On Fri, 2021-03-26 at 07:30 +0100, Nicolas Kovacs wrote:
Le 26/03/2021 à 03:09, Jyrki Tikka a écrit :
Both virt-manager and virt-clone prevent you from doing this. However, you can change the created random MAC using virsh edit on the cloned domain.
Do you mean that I can use virsh edit to define an identical MAC address for the original VM and the clone?
That's exactly what I mean. Just look up the original MAC address and use it in the interface section of the XML definition
<interface type='bridge'> <mac address='52:54:00:ba:de:91'/> <source bridge='br0'/> <model type='rtl8139'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
<(*) Jyrki
Le 26/03/2021 à 22:49, Jyrki Tikka a écrit :
That's exactly what I mean. Just look up the original MAC address and use it in the interface section of the XML definition
<interface type='bridge'> <mac address='52:54:00:ba:de:91'/> <source bridge='br0'/> <model type='rtl8139'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface>
I just found a simple solution : removing the NIC interface before cloning the VM. Then manually adding it on the clone.
Takes just 30 seconds longer to clone than with VirtualBox, but works fine.
Sometimes you have to imagine complex things before doing something very simple.
Thanks to everybody for your input,
Niki