D
D
DVoropaev2021-06-30 17:31:35
linux
DVoropaev, 2021-06-30 17:31:35

How to connect a qemu virtual machine to the main network?

On the workstation - linux, on the guest system - also linux.
I start the virtual machine like this:

emu-system-x86_64 -hda /путь_к_диску.qcow -m 1512 -vga qxl

I want the virtual machine to be on the same network as the workstation (the workstation is connected via ethernet to the router. IP is received via DHCP from the router)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-07-01
@DVoropaev

https://www.google.com/search?q=qemu+kvm+bridge+ne...
in short:
1. install the bridge-utils package
2. register the bridge in the network settings on the host, add the network adapter to the bridge; depends on how the network is configured - via netplan or the old fashioned way via /etc/network/interfaces or something else
2.1. now the bridge will be the main network interface on the host, so if there are any iptables rules, etc. not trivial settings, then this should be taken into account
3. create /etc/qemu/bridge.conf and add the line allow bridge_name
In fact, we hand-to-hand configured what is called a virtual switch in Hyper-V or in VMware.
This completes the preparatory steps, it remains to connect the virtual machine to the bridge.

qemu-system-x86_64 -hda /путь_к_диску.qcow -m 1512 -vga qxl -netdev bridge,id=имя_виртуального_адаптера,br=имя_бриджа -device virtio-net-pci,netdev=имя_виртуального_адаптера,mac=52:54:00:12:34:56

You can assign an arbitrary MAC for the virtual machine, but its first half 52:54:00 is specially reserved for qemu\kvm.
virtual_adapter_name is arbitrary.
bridge_name matches the one you specified in the settings at the beginning.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question