QEMU/Bridge with Wifi Routing

=Introduction= When there are several VMs running and the developer wants them to interact with each other, he or she creates a bridge. As discussed in QEMU/Options you can easily bridge an Ethernet with the virtual machine(s). However, there are times when the developer is using a wireless network and still want to interact with the VMs. Also, another possibility is that the network on the ethernet is desired to have an independent state from the VMs and is not included in the bridge. This guide deals with such conditions.

=Prerequisites=

Emerge the packages. Dnsmasq is not necessary but it can become very handy in case one does not want to setup the networking section of the guest and the host manually or the VMs depend on having a dhcp server running.

=Creating the Bridge= As an example, we would like to bridge two virtual machines. If there is one, then only configure it so. If more are running, they can easily be added here. Edit the main network configuration file:

The interfaces must exist so:

Finally, start the bridge networking:

=Setting up Dnsmasq= Configure dnsmasq:

Start the service

=Network options for Qemu VMs= Set the network options for the first VM like this: As you can see, the interface has been specified  and also a mac address has been set. Setting a mac address is important as it helps the VMs be distinguishable.

For the second VM it can be done in the same way but with its own interface and mac address:



Here the network adapter  has been utilized for better performance. Make sure that you have followed the necessary steps to build the driver inside the VM and provide the support in the host. For more information refer to the necessary kernel configurations in QEMU and QEMU/Linux_guest and QEMU/Windows_guest.

=The fun of routing to Wifi= At this point, the VMs should be working and they should get an IP address from dnsmasq. If they do not get the IP, consult. While they should be able to see each other from each of them, still they cannot see the outside. Neither the host can interact with them. This can even be a desired behaviour if the developer wants to have the VMs operate in an isolated network from the internet. If we had included the Ethernet interface in the bridge, the problem would have been solved, however, as it was said in the beginning, maybe one does not want to involve eth0 as it might be configured by another application or maybe the host system is connected through Wifi. In the second case simply including the wireless interface in the bridge will not work.

There are several approaches here, however, these three lines from will provide the simplest solution. What is more, the versatility is in the fact that it does not matter that what interface one wants to route to--it can be wlan0 or eth0 or whatever.

In this example, the bridge interface is br0 and the host system is connected through wlan0. First, help the traffic get through the wlan0:

Then, let the system know that the known traffic can get back at br0:

Here you are. Now the VMs can fully access outside and the host while the main host network interface is not part of the bridge.