This page was exported from Furor Teutonicus
[ https://www.furorteutonicus.eu ] Export date: Sat Apr 21 0:27:13 2018 / +0000 GMT |
Enabling host-guest networking with KVM, Macvlan and Macvtap![]() The perfect setup, nearlyYou installed your Linux server and naturally selected KVM (Kernel Virtual Machine) as hypervisor. Using virt-manager, you also created one or more guest VMs (Virtual Machines). You want fast networking. So you use the paravirtualized virtio drivers for the guests. You also want no difference between virtual and non-virtual machines. All should be able to talk over the same LAN, use the same subnet, contact the same DHCP server and talk with each other. So you use the Macvtap driver. Macvtap makes use of Macvlan, also written as MAC VLAN. MAC VLAN allows you to have multiple Ethernet MAC (Media Access Control) addresses on one NIC (Network Interface Card). Network traffic will go directly to and from the physical line to the guest VM. If you enable bridge mode, then all kind-of-virtual NICs attached to the same host (or physical NIC, I'm not sure) can see each other. It's just so much easier than having to create and manage traditional brctr bridges. And probably it performs better, too. The problem: the host cannot talk with the guestsThe guests can talk to each other. But the host is excluded from the social event. Look at the picture below. Guest 1 and guest 2 are connected using a red line; they are also connected with the eth0 physical NIC of the host. Packets delivered to eth0 will be sent to the network immediately. The hypervisor cannot intercept them. ![]() Solution: create a macvlan interface on the hostIf you create a macvlan interface on the host, and use that one instead of eth0, than the host can communicate with the guests. Some people don't like this solution because of bad integration with the NetworkManager, but I like it because I don't have to modify the guests. And I'm using only one host machine, so I can handle that with ease. I have tested this solution myself on two different computers, both running Scientific Linux 6.4 (a RHEL derivative). So beware, YMMV. What I did: I wrote a simple shell script that takes care of the creation of and routing to a macvlan interface on the host. So on the host, you have to run this script on startup, e.g. by adding the full path to the script in /etc/rc.local. Here is the script: #!/bin/bash Beware: If the underlying eth{n} link is down, then also the macvlan will go to the "down" state. That means that the hardware ethernet link must be up, otherwise macvlan/macvtap based VMs will not be able to communicate with each other, or with the host. Also, NetworkManager can play nasty on your customized routing table when the link comes up again. The resulting routing table will look like this: Destination Gateway Genmask Flags Metric Ref Use Iface Guest configurationThe guest must be configured to use macvtap in bridge mode. Typically, in the configuration XML (/etc/libvirt/qemu) you will find: <interface type='direct'> Remember that the guest will then use the DHCP server of the physical LAN. No need any more for the dnsmasq part on the hypervisor. If all your guests use this trick, then you can do: rm /etc/libvirt/qemu/networks/autostart/* That removes the bridge interfaces you see when you run ifconfig. If you cannot wait until the next reboot, also do for each network: virsh net-destroy _network-name_ AttachmentsAcknowledgements / sources
|
Excerpt: How to use macvlan on the KVM hypervisor with macvtap on KVM guests so that the host and the guests can ping each other and behave like they are all on the same subnet (LAN). |
Post date: 2013-08-04 21:51:24 Post date GMT: 2013-08-04 20:51:24 Post modified date: 2013-08-13 14:45:27 Post modified date GMT: 2013-08-13 13:45:27 |
Powered by [ Universal Post Manager ] plugin. HTML saving format developed by gVectors Team www.gVectors.com |