Wednesday, August 6, 2008

VM networking: QEMU and VMware

Sometimes you have to work with qemu and VMware virtual machines at the same time. Moreover you want these machines be visible to each other over the network.

To set up shared network environment for qemu and vmware you should prepare kernel to support TUN/TAP interfaces and bridge interfaces:
Enable TUN/TAP support:

Device Drivers  --->
   Networking support  --->
      <*> Universal TUN/TAP device driver support
Networking  --->
   Networking options  --->
      <*> 802.1d Ethernet Bridging #NOTE : at least for 2.6.20 series
Ensure that you have /dev/net/tun char device and it's writable and readable for qemu user.

Start vmnet(usually vmnet8) interface.

Set vmnet8 in promisc mode:
ifconfig vmnet8 promisc
Setup bridge interface:
brctl addbr br0
Add vmnet8 interface to the bridge:
brctl addif br0 vmnet8
Run vmware VM.

Create file /etc/qemu-ifup with:
#!/bin/sh
sudo /etc/qemu-ifup-sudo $@
Create file /etc/qemu-ifup-sudo with:
#!/bin/sh
/sbin/ifconfig $1 0.0.0.0 promisc up
/usr/sbin/brctl addif br0 $1
Make them executable and add qemu user to /etc/sudoers to run /etc/qemu-ifup-sudo in proper way.

Run qemu VM:
qemu -hda linux.img -net nic,macaddr=52:54:00:12:34:57 -net tap
For every new qemu VM instance you must set different macaddr!

No comments: