Configure qemu-system for using host side virtual bridge

bridgelinux-networkingqemustatic-ipwindows 7

I'm going to run the following setup with qemu-system as hypervisor:

Hostsetup:

Hypervisor machine (Ubuntu 16.04)           Second Machine 
qemuVm--tap0--br123--eth0--|Hardware hub|--eth42--SecondPC

So this is a network containing a virtual machine hosted by qemu-system and is connected over a tap interface to a virtual bridge. The virtual bridge is createt by the host. The virtual bridge is NOT the default bridge of libvirt/virt-manager or other systems. The virtual bridge has a real eth0 network card. This network card is connected over wire with a real hub. Connected to the hub is an other Real pc. All clients use static IP-addresses. I would like to use all services like ICMP, UDP, TCP, FTP etc. between all connected machines

IP-list:

  • win7qemuVm: 10.0.0.10
  • br123: 10.0.0.100 (I do not want to use the default bridge from qemu)
  • tap0: ? Is it possible / necessary to assign an ip address?
  • eth0: ? necessary to assign an ip address?
  • eth42 10.0.0.201 (interface of second pc)

I would like to work with -netdev / -device not with old -net nic.

Which command line parameters do I need for my win7qemuVm to connect it to the tap-device?

There are IP routes, ipforwarding and iptables. Do I need to change there default ubuntu settings to make such a network possible?

My host network is already configured like that:

iface tap11 inet manual
    pre-up tunctl -t tap0
    up ifconfig tap0 up
    down ifconfig tap0 down

auto br123
iface br123 inet static
   address 10.0.0.100
   netmask 255.255.255.0
   bridge_ports eth0
   bridge_ports tap0
   bridge_stp off
   bridge_fd 0.0
   pre-up ifdown eth0
   pre-up ifdown tap0
   pre-up ifup eth0
   pre-up ifup tap0
   post-down ifdown eth0
   post-down ifdown tap0

The network manager is disabled.

Best Answer

The upper configuration is correct to solve the problem. The first success is, when your bride / tap etc remains UP. So this say's it is used, system is running. should look like this:

$ ip link show
# Output modified and formatted:
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
   master br123 state UP 
   mode DEFAULT group default qlen 1000
   link/ether 68:05:ca:51:8e:ff brd ff:ff:ff:ff:ff:ff
5: tap0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast 
   master br123 state UP
   mode DEFAULT group default qlen 1000
   link/ether ce:c4:55:91:86:6f brd ff:ff:ff:ff:ff:ff
6: br123: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue 
   state UP mode DEFAULT group default qlen 1000
   link/ether 68:05:ca:51:8e:ff brd ff:ff:ff:ff:ff:ff

You can see the line, where master and state is mentioned, those ones are the important ones.

Next challenge is to find a network device, supporting this tap thing. I've used the virtio network device and downloaded the virtio driver for my XP. I haven't tested yet other OS and only some virtual network cards, so there might be the possibility other will work too. But important is, that not all virtual device drivers are working with tap-devices. SO for example, the network card in Windows might be up and running, but you can't get in and out any ping. If your firewall is down and everything else is configured correct, you might have added a adapter, where a tap-device is not supported.

The network connection is a 1:1 pair, so you use two steps to do so. The host side configuration starts with -netdev, where you define a network adapter connected to the (here) host. tap0 is part of this. Important is to define the ID.

This ID is used in the client side configuration where the interface for the guest is defined. -device. virtio-net-pci is the networkadapter used in this example.

exec qemu-system-x86_64 \
-enable-kvm \
-hda W_XP.img \
-m 1G \
-monitor stdio \
-cdrom /media/img/SharedImages/driver/W_XP/virtio-win-0.1.126.iso \
-netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no \
-device virtio-net-pci,netdev=mynet0,id=mynet0,mac=52:54:00:c9:18:27 \
$@

Source for Commands

Controlling State of bridge during or after machine has run

$ dmesg
[time in sec ]
[13649.332345] br123: port 2(tap0) entered blocking state
[13649.332346] br123: port 2(tap0) entered forwarding state
  machine running
[13674.309067] br132: port 2(tap0) entered disabled state
  machine stopped

I've checked the setup with following adapters with winXP SP3, all working with tap-device:

Only for some you need to install an external driver.

rtl8139 Realtak RTL8139-Familie-PCI-Fast Ethernet-NIC   
   5.398.613.2003 RTL8139.sys   100 
ne2k_pci    Realtek RTL8029(AS)-basierender Ethernetadapter (Standard)
   5.508.803.2000 RTL8029.sys   10
e1000-82545em   Intel(R) PRO/1000 MT Network Connectiion
   Intel 8.10.3.0 e1000325.sys uvm. 1000
e1000   Intel(R) PRO/1000 MT Network Connectiion
   Intel 8.10.3.0 e1000325.sys uvm. 1000
virtio-net-pci  Red Hat VirtIO Ethnernet Adapter    
   51.73.104.12600 netkvm.sys 1000