KVM: How to make VM get IP from same DHCP as host?
Linux - Virtualization and CloudThis forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
KVM: How to make VM get IP from same DHCP as host?
Hi,
I have several VMs on KVM with virtual machine manager that I don't want to use NAT with, I want them to get a IP from the same source as the host machine, from the external DHCP. For this purpose, I want to do level 2 bridging, so the virsh networking "switch" or interface is directly bridged with the physical NIC of the host OS. This has so far not worked, when setting up the bridge, it keeps asking me for an IP and range, but Level 2 bridging has no IP, level 2 is below IP and just lets all traffic through.
I think that people today confuse what a bridge is and lump together other technologies to join virtual NICs.
I have noticed that this is super simple when you use Microsoft HyperV or VirtualBox, but pretty difficult with KVM and virtual machine manager. There is hardly any documentation and nobody seems to use KVM much at all.
Right now, when I use KVM to run my VMs, they get a IP from the internal virsh DHCP and are not reachable from external machines, which is a problem.
Last edited by browny_amiga; 06-25-2021 at 04:48 PM.
I agree that VMM is somewhat less comfortable than VirtualBox, but what you say does not make much sense to me.
Quote:
Originally Posted by browny_amiga
I want to do level 2 bridging, so the virsh networking "switch" or interface is directly bridged with the physical NIC of the host OS. This has so far not worked, when setting up the bridge, it keeps asking me for an IP and range.
What keeps you asking? How exactly did you set up the virtual network?
Quote:
Right now, when I use KVM to run my VMs, they get a IP from the internal virsh DHCP and are not reachable from external machines, which is a problem.
If they are bridged, they are connected to the same network as the other devices. Except if the VM host blocks or otherwise manipulates traffic. It seems your VMs are not bridged.
To help you, I'd like to see the output of
Code:
virsh domiflist VM
where VM is one of those VMs that you have trouble with.
I agree that VMM is somewhat less comfortable than VirtualBox, but what you say does not make much sense to me.
What keeps you asking?
When I read the instructions on how to setup bridges via different means, it often has instructions to set an IP for the bridge, which does not make sense to me.
Quote:
How exactly did you set up the virtual network?
That is how the questions start, I use virt-manager on Debian 10 and I'm confused on how I can get a level 2 bridged NIC in my VM that is directly connected to the host interface.
I have to admit that I don't have much experience setting up virtual networks on KVM via virsh, virt-manager doesn't offer many possibilities.
I keep coming across macvtap, which seems to offer bridge functionality. That seems to use a more direct connection via the virtual NIC for just one VM, while there is another possibility to define a whole virtual network.
Quote:
If they are bridged, they are connected to the same network as the other devices. Except if the VM host blocks or otherwise manipulates traffic. It seems your VMs are not bridged.
Yeah, I don't think it is bridged right now.
Quote:
To help you, I'd like to see the output of
Code:
virsh domiflist VM
where VM is one of those VMs that you have trouble with.
I'm honestly pretty confused on how to setup a virtual network on KMV / QEMU, it is likely not VM specific, but applys to the whole virtual network.
I basically just want that VM to get attached to my host NIC like it was physically connected to the VM and when it sends out DHCP requests, it will get an IP the same way that the host gets one.
I actually want to use KVM and avoid virtualbox as it is the built in solution on Linux. And the VMs also work pretty well, except I have always struggled with the networking. Normally, the VMs seem to be connected to use NAT to get out to the external net, but I need these VMs to be accessible from outside (which NAT normally blocks)
Last edited by browny_amiga; 06-25-2021 at 08:47 PM.
When I read the instructions on how to setup bridges via different means, it often has instructions to set an IP for the bridge, which does not make sense to me.
Without knowing what you did to set up the network, nobody can help you. Try providing information instead of repeatedly stating that you are confused.
Without knowing what you did to set up the network, nobody can help you. Try providing information instead of repeatedly stating that you are confused.
I did not set up any network. I used the default network that was already established. That is for NAT, which does not work for my use case, it sets up a local network on the VM host that is 192.168.122.0/24, including a local DHCP for it. 192.168.122.1/24 is not accessible from outside of this VM host (192.168.1.220)
I have quite a bit of experience in TCP/IP networking, but bridging is something I have never been able to get working.
I basically don't know how you setup networking with virsh, what the options are etc. My goal is to get several guest VMs to use the DHCP server on router 192.168.1.1 (serving network 192.168.1.1/24) to get an IP that is on the same network as the VM host (192.168.1.220). I'm trying to use bridging for that, I don't know if that is the recommended way, but I don't see how DHCP discovery requests from the guest VMs could otherwise arrive at 192.168.1.1 and then have a DHCPOFFER traverse back to the guest VM. The guest VMs will all be on several different physical VM Hosts (all on network 192.168.1.1/24) that all need to get IPs in network 192.168.1.1/24
When I take a physical laptop and plug it via ethernet, it will get an IP on network 192.168.1.1/24, I need all the guest VMs to get IPs on the exact same network via the same DHCP.
This hope I have expressed myself clearly, on the risk of having included redundant and obvious details.
Do that. Your mistake is you are trying to use virsh to run the networking. You need to bypass it. Point the VM at br0 (or whatever you call it) in virt-manager. When this is done the VMs are just another machine on the lan.
Yes, that worked. I just created the bridge outside virsh, on Linux, added the ethernet interface to it, set that to promisc and set the IP on the bridge interface (I was confused on how the bridge works on the different OSI layers), then adding the virtual machine to that bridge does the trick. The default gateway still has to be changed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.