Qemu, virt-manager and bridge network

Hi everyone!

I installed and configured qemu-kvm and virt-manager following this guide [Tutorial] How to install Virt-Manager Correctly on EOS/Arch base systems and everything works fine.

However, I would need to use my virtual machines in a bridge network, both between them and with the host system.

It’s possible to do it?

When I try to setup a VM’s network in bridge mode I get this error

I think I need to create the br0 interface with nmcli, but I don’t know how.

Thanks to those who will help me!

Generally, for host → virtual, or host ← virtual, there is already a virtual bridge (usually called Virtual Network 'default' : NAT) that is created when you installed the software. You would need to find out what IP each device has and then you can use the IP to connect. If you wanted to use host names, you could edit the /etc/hosts file to add a mapping for the needed IP, on each host. Virtual ↔ virtual generally works out of the box with host names, as long as they are both on the same virtual network.

A Network bridge is much more difficult to set up, and usually only needed if you need a VM to appear as a physical host on the network. I.E. a second physical host that needs access to VM on first physical host. Depending on your network setup, you still may need to edit the hosts file to reach them by name. The following Arch wiki entry can help with a network bridge, if it is indeed needed

Network bridge

The Network Manager or Iproute2 are possibly the easiest ways to accomplish this, in that order, YMMV.

The above presumes that appropriate services are running, and any firewall ports (if running) are open, already.

Thank you for your help.
I’ll explain my setup better, it’s very simple.
I have 2 virtual machines, the first with Ubuntu and the second with Windows and it would be enough for me that they were reachable from each other.

The problem is that starting them both receive the same IP address. Of course the ping between the two machines doesn’t work either.

Ubuntu

ifconfig 
enp10s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fec0::525f:1fe:a318:bac6  prefixlen 64  scopeid 0x40<site>
        inet6 fec0::c7f:5baa:895f:29f5  prefixlen 64  scopeid 0x40<site>
        inet6 fe80::62d9:b994:1cd7:ed8a  prefixlen 64  scopeid 0x20<link>
        ether 52:54:00:3a:12:c1  txqueuelen 1000  (Ethernet)
        RX packets 184  bytes 82712 (82.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 384  bytes 56037 (56.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Windows

ipconfig

Windows IP Configuration


Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . :
   Site-local IPv6 Address . . . . . : fec0::dbf6:28c8:2b79:3cc5%1
   Link-local IPv6 Address . . . . . : fe80::b2fe:b061:541:c0ae%14
   IPv4 Address. . . . . . . . . . . : 10.0.2.15
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::2%14
                                       10.0.2.2

I tried setting the IP address manually but without success, I set the windows machine to the address 10.0.2.20 but it can’t see the ubuntu at the address 10.0.2.15 (but can navigate to internet…)

C:\Users\User>ipconfig

Windows IP Configuration


Ethernet adapter Ethernet 3:

   Connection-specific DNS Suffix  . :
   Site-local IPv6 Address . . . . . : fec0::dbf6:28c8:2b79:3cc5%1
   Link-local IPv6 Address . . . . . : fe80::b2fe:b061:541:c0ae%14
   IPv4 Address. . . . . . . . . . . : 10.0.2.20
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : fe80::2%14
                                       10.0.2.2

C:\Users\User>ping 10.0.2.2

Pinging 10.0.2.2 with 32 bytes of data:
Reply from 10.0.2.2: bytes=32 time=1ms TTL=255
Reply from 10.0.2.2: bytes=32 time<1ms TTL=255
Reply from 10.0.2.2: bytes=32 time<1ms TTL=255
Reply from 10.0.2.2: bytes=32 time<1ms TTL=255

Ping statistics for 10.0.2.2:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

C:\Users\User>ping 10.0.2.15

Pinging 10.0.2.15 with 32 bytes of data:
Reply from 10.0.2.20: Destination host unreachable.
Reply from 10.0.2.20: Destination host unreachable.
Reply from 10.0.2.20: Destination host unreachable.
Reply from 10.0.2.20: Destination host unreachable.

Ping statistics for 10.0.2.15:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),

The default network segment for me has always been 192.168.122.0/24, with a gateway of 192.168.122.1, In Virt-manager under Edit->Connection Details then Virtual Networks tab you should have a screen like this:

So at the moment

  • Do you have a bridge running on your host?
  • I would expect your default gateway to be 10.0.2.1, rather than .2 (unless you have manually set)
  • Does the network range match 10.0.2.0/24 (based on subnet shown in above posts)
  • Is your DHCP range 10.0.2.3 - 10.0.2.254
  • Is it set for NAT?
  • Do you have other networks listed in Virtual Networks?
  • Are the VMs set to use the default : NAT network?
  • Have you restarted libvirt or your machine after any edits to make sure configs running are latest?

At the moment I can’t explain why the windows machine would be able to get out, unless it is using the IPv6 route.

I think we are getting closer to the problem.

I don’t have the same network options as you and I’m using qemu:///session (user session) instead of qemu:///system

Yes, it appears that you have created a bridge through libvirt possibly. Honestly, I was never able to make that work, in a useful way. I always create my bridge through the OS itself, which then show up as an option in virt-manager when creating the VM (or can be changed on existing VMs).

I would recommend creating the default network again, the instructions and where to get the data can be found here (from Stackoverflow): Restore default network libvirt
If you create the file just make sure it is named default.xml

Again, if you want a network bridge, I would follow the link for the Arch wiki above to create through the OS.

Thanks again for the help.

This is my default.xml file

sudo cat /etc/libvirt/qemu/networks/default.xml
<!--
WARNING: THIS IS AN AUTO-GENERATED FILE. CHANGES TO IT ARE LIKELY TO BE
OVERWRITTEN AND LOST. Changes to this xml configuration should be made using:
  virsh net-edit default
or other application using the libvirt API.
-->

<network>
  <name>default</name>
  <uuid>56514044-f1e9-4b48-aa1a-14a5f9eeb61d</uuid>
  <forward mode='nat'/>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:4f:38:2e'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'/>
    </dhcp>
  </ip>
</network>

This is the error I get following the method you linked to me

sudo virsh  net-define default.xml
errore: impossibile collegarsi all'hypervisor
errore: Operazione non supportata: Cannot use direct socket mode if no URI is set

No need to thank me, especially since I haven’t “solved” anything for you.

From your previous post where you mentioned qemu:///session, something of a faint memory came to me. I looked at the link you worked from, checked my installs (all qemu:///system), and did a little research (one of the better pages). I stumbled back across that qemu:///session is running unprivileged, and networking is limited. There is a way to use virbr0 still though, as long as it is in /etc/qemu/bridge.conf, you can check yours to see that you get this.

$ cat /etc/qemu/bridge.conf 
  allow virbr0

What I don’t know, is how that might show up in the list when you choose networking for a new or existing VM. I can try spinning up a VM, running through the instructions you used later (after I get some sleep), and hopefully get back to you with a solution.

Edit: You might try in NIC setting of a VM by using setting Network source: to Bridge device…, and Device name: to virbr0 (screenshot is just where you want to be, don’t use my setting)
image

OK, sorry this took so long. When I started earlier I wasn’t quite awake, and introduced a completely unrelated issue, and followed it right down the rabbit hole. Once I came out the other side with a solution, I had steps that then didn’t seem necessary. I flattened my lab and started over, without said rabbit hole, and indeed the solution was as easy as my last post screenshot under the Edit:

To recap, in your settings for the VM, goto NIC

  • in Network source: use Bridge device...
  • in Device name: type virbr0

This will allow the VMs to communicate with each other by name or IP, and you can communicate with the host by IP. To use hostname you would need to edit the /etc/hosts file appropriately on each machine.

From your screenshot, it looks like the default connection of QEMU/KVM was deleted. You may want to add that back, in case you ever want to edit the virbr0 network with a GUI. If you decide to, just click File -> Add Connection... make sure it says QEMU/KVM, and click Connect.

1 Like

For editing the default network from the terminal, use sudo virsh net-edit default.

For a reference, here is my working default.xml (from sudo virsh net-dumpxml default):

<network>
  <name>default</name>
  <uuid>263c026a-b2a3-47e6-af9f-ac8f6848d4e2</uuid>
  <forward mode='nat'>
    <nat>
      <port start='1024' end='65535'/>
    </nat>
  </forward>
  <bridge name='virbr0' stp='on' delay='0'/>
  <mac address='52:54:00:92:8e:30'/>
  <ip address='192.168.122.1' netmask='255.255.255.0'>
    <dhcp>
      <range start='192.168.122.2' end='192.168.122.254'>
        <lease expiry='24' unit='hours'/>
      </range>
      <host mac='52:54:00:5d:52:ea' name='windows-11' ip='192.168.122.101'/>
      <host mac='52:54:00:91:37:db' name='debian-cin' ip='192.168.122.110'/>
      <host mac='52:54:00:e7:a2:3f' name='debian-kde' ip='192.168.122.111'/>
      <host mac='52:54:00:40:0e:ab' name='debian-gnome' ip='192.168.122.112'/>
      <host mac='52:54:00:a9:33:cf' name='arch-iso' ip='192.168.122.120'/>
      <host mac='52:54:00:40:20:7e' name='arch-cin' ip='192.168.122.121'/>
      <host mac='52:54:00:8c:07:95' name='arch-kde' ip='192.168.122.122'/>
      <host mac='52:54:00:9f:62:85' name='arch-gnome' ip='192.168.122.123'/>
      <host mac='52:54:00:52:80:33' name='ubuntu-cin' ip='192.168.122.130'/>
      <host mac='52:54:00:92:ce:ef' name='ubuntu-kde' ip='192.168.122.131'/>
      <host mac='52:54:00:0f:c6:79' name='ubuntu-gnome' ip='192.168.122.132'/>
      <host mac='52:54:00:5b:75:8e' name='fedora-cin' ip='192.168.122.140'/>
      <host mac='52:54:00:06:d5:b4' name='fedora-kde' ip='192.168.122.141'/>
      <host mac='52:54:00:33:bf:85' name='fedora-gnome' ip='192.168.122.142'/>
      <host mac='52:54:00:8b:2e:b8' name='opensuse-cin' ip='192.168.122.150'/>
      <host mac='52:54:00:3e:82:db' name='opensuse-kde' ip='192.168.122.151'/>
      <host mac='52:54:00:3e:e8:c6' name='opensuse-gnome' ip='192.168.122.152'/>
      <host mac='52:54:00:2b:1b:18' name='gentoo-systemd' ip='192.168.122.160'/>
      <host mac='52:54:00:3e:b7:82' name='gentoo-term' ip='192.168.122.161'/>
      <host mac='52:54:00:69:d7:27' name='gentoo-cin' ip='192.168.122.162'/>
      <host mac='52:54:00:ad:1d:b8' name='gentoo-kde' ip='192.168.122.163'/>
      <host mac='52:54:00:57:e2:49' name='gentoo-xfce' ip='192.168.122.164'/>
      <host mac='52:54:00:25:e5:a5' name='nixos-kde' ip='192.168.122.171'/>
    </dhcp>
  </ip>
</network>
1 Like

Thank you both very much, I finally solved it.
Having configured virt-manager for use as a simple user I had a bit of trouble getting things right.

To recreate the default connection I had to use the command
virsh net-edit default (without sudo and using xml file provided by @ajgringo619 )

The new virbr0 connection in user mode didn’t connect, I had to open virt-manager as root and set it to autostart.

Now everything is finally working as it should!

Thanks again!

2 Likes

Glad you got it working.

And thanks, I was able to learn about session vs system.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.