How to run multiple guest OS in QEMU?

This weekend I’ve been fiddling with

QEMU. I’ve installed OpenBSD on a single image and wanted to have two instances of it communicating via network. Installing the system was easy, but the networking setup was quite a pain. See how I did that… To make QEMU instances communicate with each other I needed to plug them to a “network”. That’s why I’ve created a bridge to which Virtual Instances would connect to.

I’ve used the following script:

# 1st, release all DHCP address and remove all IP address associated
# with the original eth0
#/sbin/dhcpcd -k
kill pidof dhclient
/sbin/ip addr flush eth0
# then take the interface down so we can rename it
/sbin/ip link set eth0 down
# now rename the original eth0 to reth0 (Real ETH0)
nameif reth0 00:24:81:43:61:5b
# OK, bring the same interface (with new name though) back up
/sbin/ip link set reth0 up
# 2nd let's create a bridge called eth0 so other programs think they are
# talking to the same old interface (actually they will talk to the
# bridge which is a clone of the original eth0 - with name MAC addr)
/usr/sbin/brctl addbr eth0
# then add both origianl eth0 and tap1 device to the bridge
/sbin/brctl addif eth0 tap1
/usr/sbin/brctl addif eth0 reth0
echo "showing bridge mac addresses"
/usr/sbin/brctl showmacs eth0
# 3rd, we need to bring the newly created bridge UP
/sbin/ip link set eth0 up
# 4th, renew the DHCP address if possible
#/sbin/dhcpcd -n
dhclient eth0
/sbin/ip addr show

Then I just needed to start Qemu with this command line:

sudo qemu openbsd-4.7.img  -net tap -net nic,macaddr=52:54:00:12:34:57,model=ne2k_pci

Since I’ve set up bridge for Qemu instances, I’ve plugged TAP interfaces into it. That’s why I’ve needed to specify this in my qemu exec line. I’ve also added macaddress setting since both my instances were getting the same one. And that’s all! It works like a charm. Now on to some harder things!

You May Also Like