QEMU/KVM Attaching a Virtual NIC Directly to a Physical Interface

Man, it took me a while to figure out how to do this! Over on Attaching a Virtual NIC Directly to a Physical Interface I figured out I could use this XML in Virtual Machine Manager (virt-manager) for my NIC device:

<interface type='direct'>
  <source dev='enp9s0' mode='bridge'/>
</interface>

That then gets expanded automatically to something like this:

<interface type="direct">
  <mac address="52:54:00:ce:5b:09"/>
  <source dev="enp9s0" mode="bridge"/>
  <target dev="macvtap4"/>
  <model type="rtl8139"/>
  <alias name="net0"/>
  <address type="pci" domain="0x0000" bus="0x10" slot="0x01" function="0x0"/>
</interface>

Update: ah, balls. This doesn’t completely work, because the guest can’t connect to the host, and vice versa, even though both the host and the guest can connect to the internet. This is a problem for another day. Maybe this or this will help?

Bridge sniffer

I’ve been having trouble getting my Pioneer FreedomBox to work and I found myself wanting a network protocol analyser so I could see what was going on.

I got myself two of these Simplecom USB 3.0 to Gigabit RJ45 Ethernet LAN Adapters and attached them to my MacBook Pro, like this:

network sniffing setup

Then I spun up a Kubuntu system in a VMWare Fusion virtual machine and created a bridge like this (thanks to my mate Raz for the instructions):

   ifconfig eth0 up
   ifconfig eth1 up
   brctl addbr br0
   brctl addif br0 eth0
   brctl addif br0 eth1
   ifconfig br0 up

Then I was able to run WireShark to monitor traffic across the br0 bridge which helped me to diagnose the issues I was facing.

…and in the end I got my FreedomBox operational, so got to be happy about that! :)

The problem I was having was that my FreedomBox would work okay for a few minutes and then lose network connectivity. I confirmed this with my WireShark logs. You could see the DHCP and MDNS working at first and then see things stop working after some time.

The problem turned out to be related to the fact that I was running an old version of the FreedomBox software. The reason my software was out of date was that I had downloaded a “nightly build” which was well out of date. I think maybe the nightly builds are no longer maintained. After I upgraded to a stable build my networking problems went away.