Girish Venkatachalam is a UNIX hacker with more than a decade of
networking and crypto programming experience.
His hobbies include yoga,cycling, cooking and he runs his own business. Details here:
I love the poor. I feel that the poor are more sensible when you see the antics of the rich. And for some reasons many Indians believe that creating wealth is sinful.
Anyway although I have several physical machines with me I still prefer not having to power them on, connect the power chord, the Ethernet chord, use a switch/hub and so on.
How about a way to create a network without any of these?
But before that we need to know where I am coming from.
I am a networking geek and I make my living solving complex networking problems. By that I mean really complex ones. In fact my product SpamCheetah itself involves quite a bit of complex networking concepts.
The other thing that I want is use skype on OpenBSD, my favorite OS. Skype runs on linux and FreeBSD using emulation. But I don't like FreeBSD.
I don't want to run linux just for skype.
But there is an additional complication here. Audio has to work. But for that I would have solved this problem long ago.
It turns out that qemu gives us this and much much more.
I am certain many of you know qemu already.
It is 100% open source and is a fabulous tool. It is fast. Real fast even on incredibly low end hardware I use.
And it supports full networking using Qemu bridge mode or TUN/TAP mode of bridging computers together.
Every qemu instance forms part of the host bridge and it will behave exactly like a computer attached to your switch/bridge.
Layer II bridging is great fun though I have only done qemu bridging and never any physical bridging. I buy some cheapo non managed switch and I am done.
This article will deal with what you need to do to setup qemu bridging so that you can run servers on your qemu instances.
I have this need.
All my products have web panels and I want to be able to access them from qemu. By default qemu will only give you the ability to talk TCP to the outside world and it will use the 10.0.0.0/8 network of the host.
This will suffice in many cases but not all.
Over a long period of time I have learned to use this switch when starting qemu for bridge mode networking.
# qemu -net nic -net tap foo.bin
Be careful here. You are running as root. And you have to write to X. So better give
$ xhost +
on your host X server which most likely will run as a normal user.
It so turns out that qemu can do even more cool things.
Like audio for instance.
But before that I had another need.
I wanted my qemu instance to run far away and I did not know how to use VNC or X from there. I did not want to , I know VNC Is not big deal.
It so turns out that qemu does brilliant serial port emulation and OpenBSD also has excellent support for it. All I had to do is change the OS to write to the serial port instead of the console. Under OpenBSD this is done by
# cat > /etc/boot.conf set tty com0 <Ctrl-D>
But on linux you need to do something different which I would not know.
And the way you start qemu is different(obviously).
$ qemu -nographic foo.bin
That is it.
It writes to the text mode terminal and it is fully functional in every way.
Now we come to audio.
Then finally wrap up this long and tedious article with how to do linux bridging with bridge-utils and uml-utilities.
For audio, just type this.
$ qemu -audio-help
It prints a lot of stuff but we need only this line.
$ export QEMU_AUDIO_DRV=sdl
And start qemu with
$ qemu -soundhw all foo.bin
You get full audio support if your host has proper audio support.
I tested this with OpenBSD as host and slax linux as guest.
It worked beautifully.
I hope to get skype working one day soon.
Now for bridging.
Install these two utilities first.
It is silly that Debian ships without them.
Anyway create a bridge like this.
# ifconfig eth0 0.0.0.0 # brctl addbr br0 # ifconfig br0 up # ifconfig br0 192.168.1.5 # brctl addif br0 eth0 # tunctl # ifconfig tap0 up # brctl addif br0 tap0 # route add default gw 192.168.1.1
Basically you need to give the eth0 address 192.168.1.5 and its gateway to br0 interface.
And eth0 and tap0 become separate nodes that participate in the bridge to obtain address by DHCP from your MODEM/router.
Usually DHCP is the norm. In case you wish to assign the IP manually that will also work.
Basically the qemu instance will be able to see all packets going on your physical network. This is a great blessing for us.
Your /etc/qemu-ifup needs these entries.
cat /etc/qemu-ifup #!/bin/sh sudo ifconfig $1 0.0.0.0 promisc up sudo brctl addif br0 $1 sleep 2
This seems to be the default in Debian.
Now start your qemu guest like this.
# qemu -net nic -net tap foo.bin
And inside the guest type,
# dhclient eth0
and find that you can obtain an IP from your MODEM. It is really cool.
At this point you find that you can not only ping your guest but also use any TCP or UDP port. You can test using netcat like me. Or run a regular Apache or whatever and test.
One more detail before we wind up.
What if you run many guests?
You need each guest to get a different IP from your MODEM using DHCP right?
For that use a MAC address other than qemu's default like this.
# qemu -net nic macaddr=00:33:45:0d:1e -net tap foo.bin
One final tip.
You can create a virtual hard disk using the qemu-img(1) command.
$ qemu-img create foo.bin 2G
You can install into it with the command
$ qemu -hda foo.bin -cdrom /iso/debian.iso
I am sure my article alone will not get you where you wanna go but it sure will take you far.
Best of luck.
If you found something useful today, please consider a small donation.
Got something to add? Send me email.
More Articles by Girish Venkatachalam © 2010-05-26 Girish Venkatachalam
If Linux can skate by the patent and copyright issues, its growth in the corporate world will continue no matter what business dislikes about the GPL. (Tony Lawrence)