I'm trying to learn different networking modes of qemu.
In user network mode, qemu will create a virtual DNS and associate IP addresses to VMs using DHCP.
The problem is that all VM that I create have same IP of so I thought maybe they are on separate network hubs. I tried to create a VM with the same net id or changing MAC, but it doesn't change the result.
Here are the commands I used to create the VMs:

kvm -m 3G -cdrom ubuntu-22.04-desktop-amd64.iso -netdev user,id=network0 -device e1000,netdev=network0,mac=52:54:00:12:34:77 -name "kvm1" 

kvm -m 3G -cdrom ubuntu-22.04-desktop-amd64.iso -netdev user,id=network0 -device e1000,netdev=network0 -name "kvm2"

With JdeHaan's advice I tried to learn what virsh does when creating a VM using Bridge mode. First, I created a bridge on the Host and created the VM using virsh with that bridge. With this method, you should enter the VM and set the IP for the interface manually. Unfortunately, the VM creation command from ps output is confusing and you can not find where the bridge is! Something like this:

qemu-system-x86_64 *** -netdev tap,fd=38,id=hostnet0,vhost=on,vhostfd=40 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:a8:7b:3b,bus=pci.1,addr=0x0
  • 1
    Pfff... I have a couple of years of experience with kvm but would not go at it that way, though your effort is admirable. Why don't you try a gui for managing vm's first (on a ubuntu/debian you can install one with 'sudo apt install virt-manager' and work from there? Once you have a vm running you can examine it's settings easily with 'ps -ef' or such. Good luck.
    – JdeHaan
    Commented Dec 12, 2022 at 13:18
  • Well ty... That is right that with virsh we can work easily, but virsh also use qemu(kvm) in background, so it should be possible to work with qemu directly (that ps -ef is nice advice). I'm curious about low level functionality of it. I wrote a personal container using linux kernel ability before, so I want to do the same to VMs.
    – mnr
    Commented Dec 13, 2022 at 5:51
  • Then I think I'm right in advising to do the large setup with virsh, approach your end result that way as close as possible, get the way it is started with ps and start working from there. Good luck.
    – JdeHaan
    Commented Dec 13, 2022 at 7:06

1 Answer 1


If you are using a DHCP server to provision the IP's I think this is your problem.

You probably cloned the VM and since Ubuntu 22.04(or 20?) it uses something called the machine-id for obtaining an address. Since the machine is a clone this ID is the same on all boxes. You either update this machine-id (via systemd-machine-id-setup) Or you change the dhcp-indentifier in your netplan config file to look something like this so it uses the MAC address for DHCP:

  version 2
  renderer networkd
      dhcp4: true
      dhcp-identifier: mac

From the netplan documentation:

dhcp-identifier (scalar)

(networkd backend only) Sets the source of DHCPv4 client identifier. If mac is specified, the MAC address of the link is used. If this option is omitted, or if duid is specified, networkd will generate an RFC4361-compliant client identifier for the interface by combining the link's IAID and DUID.

  • Ty for reply. I think I need to clarify my qestion more. Qemu have multiple network mode. In user network mode that qemu automatically create a dhcp server (first section of my qeustion), I created 2 vm. Both of them had same IP, and I think they are on different hub. In 2nd section I used virsh bridge mode, and I dont know how virsh connect my bridge to qemu
    – mnr
    Commented Dec 13, 2022 at 13:21
  • If I am reading your question correctly then you want to define a bridge in KVM, it's the virsh net-define option. Then you simple select that bridge for the VM. See linuxconfig.org/… for more details
    – proxx
    Commented Dec 13, 2022 at 13:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .