Easiest Way To Get Real IP Address In QEMU/KVM Windows Guest
Learn how to give a Windows Guest a real IP address on your local LAN using Qemu/KVM on a Linux computer with a WiFi network.
Get A Dongle
I’ve recently switched to KDE Neon full time and I love it. You’ll see articles scattered throughout the site about WSL2 (which is great) and Ubuntu 20.04 LTS which is also great. But Ubuntu 20.04 has one major issue I don’t like and that’s the really old KDE Plasma. Well, it’s maybe not ‘really’ old, but after my delving into Artix Linux and the more up to date version of Plasma on there, I went for KDE Neon. Ubuntu 20.04 with the latest Plasma. Bliss.
But. I still need Windows occasionally. Someone please convince Serif to create Affinity Designer and Affinity Photo for Linux. I’ll pay again, I don’t mind. Yes, yes, Inkscape and The GIMP. But no. Sorry, AD and AP are polished, great interface and I really enjoy using them.
So I need a Windows VM.
QEMU/KVM or VirtualBox?
I’m no fan of Oracle but this isn’t anti-Oracle bias, I just prefer the way Qemu/KVM is integrated into Linux more tightly. It seems to be marginally faster (particularly if you use the VirtIO drivers and install the Windows VirtIO Guest addons). But most importantly, for me at least, I don’t need to add additional kernel modules for networking and video and so on. Qemu/KVM just works.
But Qemu/KVM is an absolute pain to configure bridged networking on. It’s doable, on ethernet. Most sources I found online said it wasn’t possible at all with WiFi – so that’s most laptops knackered then. I couldn’t find anywhere that would allow DHCP connections with the bridge either, but that may be just because no-one had actually done it. Three quarters of the articles I came across are regurgitated from somewhere else too to be fair. Nice one Google. Rank one, rank them all. You must know who the original is so stop ranking all the copycats please!
So if you want bridged networking, VirtualBox is definitely easier to setup – so long as the modules compile. And they work on WiFi. If you want more raw speed and a tighter integrated feel with Linux host, well it’s Qemu/KVM. I want both!!
A Solution. It’s Not Free Though
In the end, I stuck with Qemu/KVM and added a TP-Link Archer T4U USB3 WiFi dongle on to my laptop. I then used the Hardware Passthrough option of Qemu/KVM to just allow the Windows Guest to have exclusive access to it.
Now the Windows guest connects to it’s own WiFi adapter and doesn’t actually go through the Qemu/KVM virtual network at all. The Windows guest gets it’s own DHCP assigned IP address, which is a real address from the network and can therefore be seen on the network by other machines.
Importantly for me, and one of the reasons I needed the Bridged approach, is that the HP Printer drivers didn’t appear to work at all when using the NATted network that is assigned by default to Qemu/KVM machines. This makes sense because to all intents and purposes the machine is on its own separate LAN, which has no printers.
How To Passthrough the USB WiFi To KVM
Open up the virtual machine – don’t start it, just open it in Virt-Manager. Click the Show Virtual Hardware Details icon in the toolbar. At the bottom left corner you should see an Add Hardware button. Click that. Then choose USB Host Device. Then choose your USB WiFi dongle. In my case it shows as TP-Link 802.11n NIC. But yours will say something different (unless you bought a T4U too!).
That’s it. When you start your Windows VM it’ll see the USB device just as if it was plugged in to the machine directly.
The Only Downside…
KVM will refuse to start the virtual machine if the USB device is removed. If you decide you don’t need it and want to unplug it, you’ll need to remove it from the Virt-Manager screen again in order to start without it attached. It’s not hugely burdensome because adding it back is so easy.
In my case, I unset the Link State option in the NIC section on my Virt-Manager so if I unplug the WiFi I can just set Link State active again and go straight back to the NAT scenario we’re all familiar with.
Share Files Between Host and Guest
This is easily done with VirtualBox but is a pain in the butt with Qemu/KVM too, involving WebDAV and much fiddling. With the Windows guest having a real network adaptor and a real IP address it just shows up in the Dolphin network browser if you share a folder using standard Windows sharing. It’s pretty reasonably performant too – certainly enough for what I want to do with it. I copied a file from Windows guest to Linux host at about 15Mbytes per second. This equates to approximately 150mbps. Not great if you want to shove huge video files around, but perfectly acceptable for a couple of hundred megabytes here and there.
Why The TP-Link Archer T4U
Simply put, it’s one I had laying around. Windows 10 finds it straight away with no driver downloads and it just worked. But so should any USB3 WiFi adaptor you can find on Amazon or eBay. Since Linux isn’t using it you do not need any Linux drivers. Which is just as well because the TP-Linux drivers for the T4U are hideously out of date and won’t run on modern Linux distributions.
For around $20-$30 you can give your Windows 10 Guest its own IP address and connect directly to your local WiFi lan without needing to mess around with Qemu/KVM wireless network bridging. Plug in the dongle, redirect the USB host device and boot up Windows. Jobs a good ‘un.