Category Archives: Networking

Using bridged networking with KVM/QEMU guests on a Linux host

Using KVM to virtualize guest operating systems under Linux is great, but the default networking configuration doesn’t allow incoming connections to the VM. This is not peculiar to KVM – this is the default for most (all?) virtualization technologies, including VirtualBox.

If, like me, you need to access you guest VM’s from the outside, then you need to setup bridge networking. There are plenty of resources on the web on how to do this, and this blog is simply a quick overview of the steps I took to enable bridge networking under KVM. It will serve as a reminder to my self of the steps I took, and possibly help others out as well.

Below is a list of the sites I used for setting up bridged networking with KVM under Linux:

https://help.ubuntu.com/community/NetworkConnectionBridge
http://drupal.bitfunnel.net/drupal/macosx-bridge-qemu
http://en.blog.guylhem.net/post/88201449689/running-qemu-with-tap0-and-nat-under-osx-109
http://superuser.com/questions/42249/how-to-bridge-two-ethernet-ports-on-mac-os-x

In a nutshell, setting up a bridge on Linux means installing the necessary bridge software and editing the /etc/network/interfaces file, both of which are described here:

https://help.ubuntu.com/community/NetworkConnectionBridge

If you’re like me, seeing a working config file gets you a long way, so below is my /etc/network/interfaces file. For reasons not related to bridging, my network is setup as a class B network, so you will probably have to adjust the various addresses accordingly:

$ cat /etc/network/interfaces

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

iface eth0 inet manual

auto br0
iface br0 inet static
    address 172.16.0.190
    network 172.16.0.0
    netmask 255.255.0.0
    broadcast 172.16.0.255
    gateway 172.16.0.1
    dns-search mydomain.com
    dns-nameservers 172.16.0.10
    bridge_ports eth0
    bridge_stp off
    bridge_fd 0
    bridge_maxwait 0

Once bridging is setup on the Linux host, all that needs to be done is start QEMU with the correct network options, and then edit the guest network settings. The options to use for QEMU are:

-net nic,vlan=0
-net tap,vlan=0,ifname=tap0

Note that these options replace the existing QEMU network options, and are not to be used in conjunction with them.

It is these args that inform QEMU that you wish to use bridged networking.

To use bridge networking on Windows 7, add the above two arguments to your QEMU start line and then setup your network manually within Windows 7. For example, if you use this command for non-bridge networking:

qemu-system-x86_64 -enable-kvm -m 8192M -cpu host -drive file=/dev/zvol/rpool/kvm/windows7/disk0 -netdev user,id=vlan0 -net nic,model=e1000,netdev=vlan0 -smp 2

Then use this for bridged networking:

qemu-system-x86_64 -enable-kvm -m 8192M -cpu host -drive file=/dev/zvol/rpool/kvm/windows7/disk0 -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 -smp 2

Note that this assumes you have previously setup bridge networking support in Linux. Also, you must run QEMU as root in order to use bridge networking.

To use bridge networking on OS X Mountain Lion, use the above two arguments for networking in your QEMU start line. For example:

qemu-system-x86_64 -enable-kvm -m 4096 -cpu core2duo -machine q35 -usb -device usb-kbd -device usb-mouse -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" -kernel ./chameleon_svn2534_boot -smbios type=2 -device ide-drive,bus=ide.2,drive=MacHDD -drive id=MacHDD,if=none,format=raw,file=/dev/zvol/rpool/kvm/mountain-lion/disk0 -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 -monitor stdio -smp 2

And then setup your network manually within Mountain Lion using these commands:

sudo ifconfig bridge0 create
sudo ifconfig bridge0 addm en0
sudo ifconfig bridge0 up

These commands aren’t necessary, but may be useful if you make a mistake:

sudo ifconfig bridge0 down
sudo ifconfig bridge0 deletem en0
sudo ifconfig bridge0 destroy

To use bridge networking on OS X Mavericks, use the OS X Network utility as described in the above posts to add a bridge, making sure to add your Ethernet device (en0) to it. Then add use the two QEMU networking options above in your QEMU command-line along with the virtio driver. For example:

qemu-system-x86_64 -enable-kvm -m 4096 -cpu core2duo -machine q35 -usb -device usb-kbd -device usb-mouse -device isa-applesmc,osk="ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" -kernel ./chameleon_svn2534_boot -smbios type=2 -device ide-drive,bus=ide.2,drive=MacHDD -drive id=MacHDD,if=none,format=raw,file=/dev/zvol/rpool/kvm/mavericks/disk0 -net nic,model=virtio,vlan=0 -net tap,vlan=0,ifname=tap0 -monitor stdio -smp 2

UltraSPARC 60 Timeout waiting for ARP/RARP packet

So my UltraSPARC 60 kept wanting to boot from the net despite the boot-device being set properly. Turns out that the diag-switch? was set to true, presumably because an invalid checksum was detected & so the default values were loaded:

Incorrect configuration checksum;
Setting NVRAM parameters to default values.

Sure enough, my ethernet and host id were lost:

The IDPROM contents are invalid

(2 X UltraSPARC-II 450MHz), No Keyboard
OpenBoot 3.29, 1024 MB memory installed, Serial #0.
Ethernet address 0:0:0:0:0:0, Host ID: 00000000.

To fix the boot issue, I simply reset the diag-switch?:

{0} ok printenv diag-switch?
diag-switch? =        true

{0} ok setenv diag-switch? false
diag-switch? =        false

To fix the address and host id:

{0} ok 57 f mkp
{0} ok 8 0 20 b8 96 ef 80b896ef mkpl
Ctrl-D Ctrl-R
{0} ok
{0} ok .idprom

If you see a Copyright message after pressing Ctrl-D Ctrl-R, the sequence didn’t work and should be repeated. When successful, the .idprom command will show the address you just entered.

Of course, I didn’t have my original MAC address memorized, so I just based them off another UltraSPARC I had lying around. In the end, so long as it’s in the correct format and unique in your network, I don’t think it matters.

Finnally, I rebooted the system:

{0} ok reset-all

Note that in my case, it turned out that the NVRAM battery was dead, so powering off the system caused the problem to reoccur. But if you don’t power off the system, the above commands will get you up & running until you can replace the NVRAM. I haven’t ordered a new NVRAM yet, but my research shows it is Sun part #525-1430.

NetBSD "mount_nfs: rpcbind to nfs on server: RPC: Program not registered" error

All of a sudden, my NetBSD 6.1.2 SPARC NFS client failed to mount my FreeNAS share with this error:

mount_nfs: rpcbind to nfs on server: RPC: Program not registered

The only thing that recently changed was I upgraded my FreeNAS server from 8.3 to 9.2. Since several of my other NFS clients were able to connect to the share, I was doubtful the upgrade was the problem.

After a lot of digging, the problem turned out that I now needed to mount the share with the TCP option. So adding tcp as an option to my /etc/fstab fixed the problem.

nas:/mnt/volume1/backup /backup nfs tcp,rw 0 0

Based on this, I can only conclude some default changed in FreeNAS that forced me to have to add the tcp option to my NetBSD box.