How to make a Virtual Machine present itself to my home network as if it were another physical computer

Problem summary

  1. My Fedora Virtual Machine creates it’s own network on a different IP range to my home network
  2. I have managed to link it to my network so I can see my normal network shares within it, thanks to superb support in this forum. This is a fully adequate solution, but ideally…
  3. I would like it to appear on my home network as if it were a physical machine, so I can manage it using my normal network management tools, eg Router Settings (in as far as possible)

Any help you are able to give would be much appreciated.

What I did and what happened

  1. In F40 host created Boxes Win 7 guest virtual machine from Virtual Box .vdi file, using Boxes add function and choosing to add from image file. Worked fine.
  2. Installed Samba in F40 host from command line, and edited config file to create shared folder. Transferred VM to Virtual Machine Manager, and gained access to my folder shares with help from this forum.
  3. Ran Ipconfig from Win 7 guest, and found virtual machine sat on it’s own network range 192.168.124.x, not my home network 192.168.1.x, presumably with it’s own DCHP.
  4. Checked my Unifi network management software, and saw the VM was not listed as a client, and so was not able to be managed via router settings etc in that software.

What I tried to fix it

  1. Assumed Boxes had created virtual NAT mode network. Felt best solution probably to change network to fully bridged mode, so the VM would be a first class member of my home network and I could gain access from/to it, and manage it accordingly.
  2. Installed Virtual Machine Manager to give more control than Boxes over network settings
  3. Opened QEMU/KVM user session and was able to run my Win 7 Boxes VM, called ‘w7ox32’
  4. Hoped that in QEMU/KVM User Session - Connection Details window, Virtual Networks tab the connection used by the VM would be displayed and I could change the mode to bridged (as I have before using VMware).
  5. But no connection showed, though checking the W7ox32 on QEMU/KVM User Session/View/Details/NICs information the VM seemed to be using the /etc/libvirt/qemu/networks/default.xml settings.
  6. Noted warning about direct editing of this file, and Red Hat documentation seeming to suggest only two network modes ‘routed’ and ‘nat’ were valid for this file, fully bridged mode requiring other changes (?to a domain file?) and thought I had better take advice
  7. Tried a few other things suggested from posts on the web, including checking that a bridge existed and was enabled, but no luck with them either. Can post details on request

System Details

  1. Software: Fedora 40 Gnome default interface, last updated about 1 week ago, running from USB. Added BTRFS assistant, Samba, Gparted, Bridge-utils, Virtual Machine Manager
  2. Computer: Dell 8300 3.4 Ghz with 16G RAM, several hard disks and some resources (inc some VMs) on USB (v2.x)s.
  3. Network. Unifi wireless and wired/homeplug-based. Unifi so/ho Router and network management software. DHCP: 192.168.1.x/24.

Just to add that when I asked this question in the topic that resolved my shared folders issue, it was very sensibly suggested by Vladislav Grigoryev here: that I post a separate topic on it.

And that, in that, in the same topic an initial pointer to the solution was provided in this post by Villy Kruse here:

I use bridged mode for all my VMs so that they appear on my home network as you want to do.

Have you setup the bridged network interface?

In virtman in the config for a VM I select the NIC

  1. set Network source: to Bridge device...,
  2. set Device Name: to bridge1 (my bridge)
1 Like

Thanks very much for your reply.

Yes I did not explicitly set it up (see first post for VM history), but I would seem to have an active bridge, that is the strange thing. XML from the NIC section, Virtual Machine Details in the running Win 7, name: ‘w7ox32’, VMM:

<interface type="bridge">
  <mac address="52:54:00:27:42:7f"/>
  <source bridge="virbr0"/>
  <target dev="tap0"/>
  <model type="rtl8139"/>
  <alias name="net0"/>
  <address type="pci" domain="0x0000" bus="0x02" slot="0x01" function="0x0"/>
</interface>

But if I look under User Session ~ Connection Details, no connection is displayed

virbr0 is a bridge, but it is an island. VM’s connect to it via vnetx interfaces, so they can talk with each other within the 192.168.124.x/24 network, and are NAT-routed to your LAN and internet. The routed variant is alternative, but you’re still a level away from your normal LAN and you have to add a route to the 192.168.124.x network on your internet router and add (packaged) firewalld policies to enable forwarding,
The proper way is to create a bridge, e.g. bridge0 in NetworkManager and add your LAN interface to it. The bridge now connects via DHCP to the router, the network interface is just bridge slave. Any VM connected to THIS bridge is now part of your LAN. Note: due to hardware limitations, this is NOT possible if you are WiFi connected.

1 Like

Thanks very much for your reply.

Ah that explains what I see in Virtual Machine Manager. Or part of what I see.

  • Would you have any idea why I don’t see any connection in User Session ~ Connection Details?

My physical computer is connected both wirelessly and via a wired (homeplug) connection. But the wireless connection is faster, so I would be loth to sacrifice it.

  • Out of interest, what are the hardware limitations? I thought that whether a connection was wireless or not did not affect it’s ability to provide services to the OS?

In case I decide to have a go…

If so it is quite complex.

  • Is there a simpler guide that shows exactly how to set up a standard bridged connection for a Virtual Machine manager VM?

I found this one, which sounded pertient, but wasn’t sure it was appropriate for my application. How to set up a network bridge for virtual machine communication. And it uses nmtui, whereas others mention nm-connection-editor.

  • Does it look right to you?

Sorry to have so many questions, but this area is quite complex for the average user!

Here’s the CLI method for setting up a bridge:

# Create bridge
sudo nmcli connection add type bridge \
    connection.id bridge ifname br0 bridge.stp no
sudo nmcli connection add type ethernet \
    connection.id ether master bridge
sudo nmcli connection up bridge
sudo nmcli connection up ether

# Delete old connection
sudo nmcli connection show
sudo nmcli connection delete "Wired connection 1"

# Allow using bridge in session mode
sudo tee -a /etc/qemu/bridge.conf << EOF > /dev/null
allow br0
EOF

# Update VM config
virsh list --all
virsh shutdown win7
EDITOR="sed -i -e /bridge=/s/virbr0/br0/" virsh edit win7
virsh start win7

Disabling STP helps avoid delays during connection activation.
Deleting the old Ethernet connection prevents race conditions.

3 Likes

It is the same thing, just with a different user interface.

In the end you should end up with

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:b2:d5:33 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 08:00:27:b2:d5:33 brd ff:ff:ff:ff:ff:ff

when running ip link.

The original configuration for you ethernet link should be removed as its role is taken over by the link device.

Thanks very much. That looks simple - no config needed? I guess it can just pick up the config from my home network?

Sorry to be dumb, but I have limited knowledge. You mean click remove hardware here? Then add and select the new bridge in the new NIC settings?

I see some people saying that performance has gone down after making the change - I guess this or the stp is the reason?

Kind regards. Mouse

Ah thanks very much, that explains it. Will try if I need to change driver setup from command line defaults.

The virbr0 contains the DHCP server, so VM’s are local and invisible for NetworkManager and the router.

Concerning the wireless, is seems to have to do with 3-address mode. The Wifi adapter is designed to communicate with it’s own MAC, not something behind it. If you switch the adapter to 4-address mode, it can be bridged, but on my consumer setup it cause breakdown of all communications, access point and all devices should support it. No idea about homeplug. The rest is already answered, I think.

The Redhat guide explains nm-connection-editor, which is desktop-environment independent.
With this, creating a bridge is easy.

Thanks very much I think I understand now, though I am not sure. Your shell commands

  • create a pre-configured bridge, ‘br0’, delete and replace the main current physical wired connection ‘ep2s0’ by one called ‘ether’ which references the bridge ‘br0’
  • edit the virtual Win7 connection to include a reference to the bridge ‘br0’.
  • Thus connecting ‘ether’ to ‘br0’ to ‘win7’

Is that correct?

If so I guess putting your two sets together so as to avoid race conditions, command order would be:

sudo nmcli connection add type bridge \
    connection.id bridge ifname br0 bridge.stp no
nmcli connection show
nmcli connection delete enp2s0
sudo nmcli connection add type ethernet \
    connection.id ether master bridge
sudo nmcli connection up bridge
sudo nmcli connection up ether
virsh list --all
virsh shutdown win7
EDITOR="sed -i -e /bridge=/s/virbr0/br0/" virsh edit win7
virsh start win7

Is that correct? Also just to check what is the significance of the \ and indented lines? And does the EDITOR= line append a line to Win7? (I am not familiar with that command line syntax)

I will save a root (& home?) snapshot using BTRFS assistant, so if I mess up I can revert.

BTW I also have a wrireless connection wlpls0b1 - will that cause problems as h.janssen found? I would like to retain it if I can.

Sorry about all the questions - I am very much a Fedora newbie, I’m afraid.

I will have a go at this tomorrow, as it’s late here now in the UK. Many thanks again for all your help.

A \ allows for a single line of script to be split over an extra line.
The indent is to make the code nice to read, its not signifiant.
The following two echo commands are the same:

echo a    b    c
echo a \
 b \
 c

The extra spaces are removed when the shell parses the lines.

1 Like

Added gnome-boxes, libvirt, networking

Thanks very much for your answers. My Wifi is a Unifi Soho setup, but the computer wifi adapter is very much a home unit, I guess will have the same limitations as yours.

Homeplugs connect by wire to the computers ethernet card, so I guess should not be affected by the same limitations as Wifi?

I’ll certainly consult the guide if I need to use the GUI editor, thanks.

Any idea why Virtual Machine Manager (VMM) show no User Session connections? Maybe because the Vm was brought across from Boxes (and before that from Virtual Box). Do I need to register the connection with VMM in some way?

Basic test (could cause communication loss), as root:

ip link add bridge1 type bridge
ip link set bridge1 up
ip link set wls1 master bridge1
Error: Device does not allow enslaving to a bridge.

If the wifi is part of wireless distribution system or mesh, it might work.

I got also the solution presented in https://gist.github.com/gdamjan/ed095763b8c322ee5bed17e11bbaed6d running. I did just manual IP/DNS/Gateway config, no DHCP, with a /32 address on the ipvtap adapter to prevent disturbing routing, but in the VM the /24 LAN subnet just works.

For some reason a IPv6 router advertisement came into the VM, but routing did not work, so I just disabled IPv6 until I understand how a ipvtap handles IPv6, if it does.

Some libvirt features only work in system mode:

virt-manager -c qemu:///system

See also: Libvirt polkit rule doesnt work? - #9 by vgaetera

That sorted it, thanks very much :slight_smile: I now get ‘default’ displayed.

If possible could you check if I have got the below correct before I try this, as I’d like to understand what I am doing, and don’t want to mess up by getting things in the wrong order.

OK so run them end to end as I show below?

Will this process disable my F40 wireless connection, or will it just mean I cannot take advantage of it from the VM?

Thanks very much indeed for your assistance.

1 Like

Routing path is normally selected using the smallest metric value.
Wired interfaces typically have smaller metric than wireless.
I suspect that your wireless connection is ignored when the wired is active.
You can check it like this:

# Metrics for each default route
ip route show default

# Interface used by default
ip route get 1