betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

09 June 2012

A Simulated Network with Qemu and Sockets

Set it up fast and simple

I was trying to test some networking stuff with various operating systems. I have neither the patience nor the hardware to set up a bunch of real machines with those systems to try out things. So qemu came to my mind to simulate these things - which would be good enough for my problem case.

According to my study of the various parts of documentation on qemu, the fastest way to get this going was to set up a "socket" based network. That way, a couple of virtual machines can share a virtual network. They don't have access to the host's network connection - and therefore to the Internet though - unless you set up one of the guest OS systems as a router and set up some routing. I wasn't going to do that, as in my problem case a bit of isolation is a good thing.

My first machine is running some oldish variant of Linux. There isn't much special about it in that sense. This machine is the one that is set up as a "socket listener" in the command line:


qemu-system-x86_64 -nographic -no-acpi \
-m 1024 -clock unix \
-net nic,model=rtl8139,macaddr=52:55:01:4e:79:28 \
-net socket,listen=:1234 \
-hda lunix_hda.img

Basically it's a normal qemu command, the only thing different from usual is that we're not specifying the default "user" type of network, we're using "socket". This means that the vm will listen on port 1234 on the host operating system ( is implied here).

The second machine is running good ol' Windows 2000 - guess why a bit of isolation is a good thing. Here too, the setup is pretty much standard. Note that I'm specifying MAC addresses - apparently if I don't do that, all virtual systems will get the same MAC address, which is not a good thing in a network. The socket network setup is there too:


qemu-system-i386 -m 512 \
-net nic,vlan=0,model=ne2k_pci,macaddr=52:54:00:12:34:58 \
-net socket,connect= \
-monitor stdio w2kdisk.qcow2

I'm not sure it's necessary to specify here, but it was like that in the docs. We do not set it to "listen", we set it to "connect" on this machine.

Now these two virtual machines will live in the same network, it's as if they were connected with ethernet cables. They do not have any IP addresses yet though - when using the "socket" networking in qemu, the built-in DHCP server from the "user" network is not activated. No problem though, on Windows just go to the control panel and set up an IP address and netmask (no router, name server or anything else required). Set up a different IP in the same network range and netmask on the other machine (on Linux with ifconfig). Now they can ping each other and as a test the windows machine can telnet to port 22 of the Linux system.

More machines could be set up to this system and you could even set up more virtual ethernet cards and hook them to more virtual networks, or route them through the host system to the Internet.

Posted by betabug at 22:10 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Underwater | Main | Eating Out in the Labyrinth >>
There are no comments.
You can trackback to:
There are no trackbacks.